mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-07 14:44:45 +02:00
Updated Tutorial (markdown)
@@ -34,7 +34,7 @@ To keep things simple we'll put everything in a single file.
|
|||||||
return number <= 1 ? number : Factorial(number-1)*number;
|
return number <= 1 ? number : Factorial(number-1)*number;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "example/factorial", "The Factorial function should return the factorial of the number passed in" ) {
|
TEST_CASE( "example/factorial", "The Factorial function returns the factorial of the number passed in" ) {
|
||||||
REQUIRE( Factorial(1) == 1 );
|
REQUIRE( Factorial(1) == 1 );
|
||||||
REQUIRE( Factorial(2) == 2 );
|
REQUIRE( Factorial(2) == 2 );
|
||||||
REQUIRE( Factorial(3) == 6 );
|
REQUIRE( Factorial(3) == 6 );
|
||||||
@@ -53,7 +53,7 @@ What is the bug? Well what is the factorial of zero?
|
|||||||
Let's add that to the test case:
|
Let's add that to the test case:
|
||||||
|
|
||||||
```C++
|
```C++
|
||||||
TEST_CASE( "example/factorial", "The Factorial function should return the factorial of the number passed in" ) {
|
TEST_CASE( "example/factorial", "The Factorial function returns the factorial of the number passed in" ) {
|
||||||
REQUIRE( Factorial(0) == 1 );
|
REQUIRE( Factorial(0) == 1 );
|
||||||
REQUIRE( Factorial(1) == 1 );
|
REQUIRE( Factorial(1) == 1 );
|
||||||
REQUIRE( Factorial(2) == 2 );
|
REQUIRE( Factorial(2) == 2 );
|
||||||
@@ -65,7 +65,7 @@ Let's add that to the test case:
|
|||||||
Now we get a failure - something like:
|
Now we get a failure - something like:
|
||||||
|
|
||||||
```
|
```
|
||||||
Example.cpp:291: Factorial(0) == 1 failed for: 0 == 1
|
Example.cpp:9: Factorial(0) == 1 failed for: 0 == 1
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that we get the actual return value of Factorial(0) printed for us (0) - even though we used a natural expression with the == operator. That let's us immediately see what the problem is.
|
Note that we get the actual return value of Factorial(0) printed for us (0) - even though we used a natural expression with the == operator. That let's us immediately see what the problem is.
|
||||||
|
Reference in New Issue
Block a user