49 throw std::invalid_argument(
"Maximum n value is 20");
53 uint64_t accumulator = 1;
71 std::cout <<
"Exception case test \n"
73 "Expected output: 1 \n\n";
77 std::cout <<
"Base case test \n"
79 "Expected output: 1 \n\n";
83 std::cout <<
"Small number case test \n"
85 "Expected output: 120 \n\n";
89 std::cout <<
"Medium number case test \n"
91 "Expected output: 3628800 \n\n";
95 std::cout <<
"Maximum case test \n"
97 "Expected output: 2432902008176640000\n\n";
101 std::cout <<
"Exception test \n"
103 "Expected output: Exception thrown \n";
105 bool wasExceptionThrown =
false;
108 }
catch (
const std::invalid_argument&) {
109 wasExceptionThrown =
true;
111 assert(wasExceptionThrown);
113 std::cout <<
"All tests have passed successfully.\n";
static void test()
Self-test implementations to test iterativeFactorial function.
uint64_t iterativeFactorial(uint8_t n)
Calculates the factorial iteratively.