[Updated] test: add test for fibonacci() function

Fixed the errors as suggested by the author.
This commit is contained in:
fzxutar
2020-08-15 12:51:06 +08:00
committed by GitHub
parent 4c0b1a76b5
commit cc64ca66b0

View File

@@ -14,7 +14,7 @@
/**
* Recursively compute sequences
*/
int fibonacci(unsigned int n) {
unsigned int fibonacci(unsigned int n) {
/* If the input is 0 or 1 just return the same
This will set the first 2 values of the sequence */
if (n <= 1)
@@ -27,29 +27,30 @@ int fibonacci(unsigned int n) {
/**
* Function for testing the fibonacci() function with a few
* test cases and assert statement.
*/
void test() {
int test_case_1 = fibonacci(0);
* @returns `void`
*/
static void test() {
unsigned int test_case_1 = fibonacci(0);
assert(test_case_1 == 0);
std::cout << "Passed Test 1!" << std::endl;
int test_case_2 = fibonacci(1);
unsigned int test_case_2 = fibonacci(1);
assert(test_case_2 == 1);
std::cout << "Passed Test 2!" << std::endl;
int test_case_3 = fibonacci(2);
unsigned int test_case_3 = fibonacci(2);
assert(test_case_3 == 1);
std::cout << "Passed Test 3!" << std::endl;
int test_case_4 = fibonacci(3);
unsigned int test_case_4 = fibonacci(3);
assert(test_case_4 == 2);
std::cout << "Passed Test 4!" << std::endl;
int test_case_5 = fibonacci(4);
unsigned int test_case_5 = fibonacci(4);
assert(test_case_5 == 3);
std::cout << "Passed Test 5!" << std::endl;
int test_case_6 = fibonacci(15);
unsigned int test_case_6 = fibonacci(15);
assert(test_case_6 == 610);
std::cout << "Passed Test 6!" << std::endl << std::endl;
}