// from https://github.com/catchorg/Catch2/blob/devel/examples/010-TestCase.cpp // 010-TestCase.cpp #include #include "lmath/factorial.h" /* * n n! * 0 1 * 1 1 * 2 2 * 3 6 * 4 24 * 5 120 * 6 720 * 7 5,040 * 8 40,320 * 9 362,880 * 10 3,628,800 * 11 39,916,800 * 12 479,001,600 * 13 6,227,020,800 * 14 87,178,291,200 * 15 1,307,674,368,000 * 16 20,922,789,888,000 * 17 355,687,428,096,000 * 18 6,402,373,705,728,000 * 19 121,645,100,408,832,000 <<--- limit of uintmax_t * 20 2,432,902,008,176,640,000 * 21 51,090,942,171,709,440,000 * 22 1,124,000,727,777,607,680,000 * 23 25,852,016,738,884,976,640,000 * 24 620,448,401,733,239,439,360,000 * 25 15,511,210,043,330,985,984,000,000 */ Factorial f; TEST_CASE( "Factorial of 0 is 1 ", "[factorial]" ) { REQUIRE( f.fact(0) == 1 ); } TEST_CASE( "Factorials of 1 and higher", "[factorial]" ) { REQUIRE( f.fact(1) == 1 ); REQUIRE( f.fact(2) == 2 ); REQUIRE( f.fact(10) == 3'628'800 ); // uncomment to see what a fail looks like: //REQUIRE( f.fact(20) == 2'432'902'008'176'640'000 ); }