From 2882b7bec2aad61bd42912d2262696aebec3648c Mon Sep 17 00:00:00 2001 From: Filip Hlasek Date: Tue, 25 Aug 2020 16:56:49 -0700 Subject: [PATCH] fix: math/fibonacci linter warnings. (#1047) * fix: math/fibonacci linter warnings. * updating DIRECTORY.md * doxygen * unit64_t instead of unsigned int Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> --- math/fibonacci.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/math/fibonacci.cpp b/math/fibonacci.cpp index 493523b6..4e3c15de 100644 --- a/math/fibonacci.cpp +++ b/math/fibonacci.cpp @@ -13,12 +13,15 @@ /** * Recursively compute sequences + * @param n input + * @returns n-th element of the Fbinacci's sequence */ -unsigned int fibonacci(unsigned int n) { +uint64_t fibonacci(uint64_t 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) + if (n <= 1) { return n; + } /* Add the last 2 values of the sequence to get next */ return fibonacci(n - 1) + fibonacci(n - 2); @@ -30,27 +33,27 @@ unsigned int fibonacci(unsigned int n) { * @returns `void` */ static void test() { - unsigned int test_case_1 = fibonacci(0); + uint64_t test_case_1 = fibonacci(0); assert(test_case_1 == 0); std::cout << "Passed Test 1!" << std::endl; - unsigned int test_case_2 = fibonacci(1); + uint64_t test_case_2 = fibonacci(1); assert(test_case_2 == 1); std::cout << "Passed Test 2!" << std::endl; - unsigned int test_case_3 = fibonacci(2); + uint64_t test_case_3 = fibonacci(2); assert(test_case_3 == 1); std::cout << "Passed Test 3!" << std::endl; - unsigned int test_case_4 = fibonacci(3); + uint64_t test_case_4 = fibonacci(3); assert(test_case_4 == 2); std::cout << "Passed Test 4!" << std::endl; - unsigned int test_case_5 = fibonacci(4); + uint64_t test_case_5 = fibonacci(4); assert(test_case_5 == 3); std::cout << "Passed Test 5!" << std::endl; - unsigned int test_case_6 = fibonacci(15); + uint64_t test_case_6 = fibonacci(15); assert(test_case_6 == 610); std::cout << "Passed Test 6!" << std::endl << std::endl; } @@ -58,7 +61,7 @@ static void test() { /// Main function int main() { test(); - int n; + int n = 0; std::cin >> n; assert(n >= 0); std::cout << "F(" << n << ")= " << fibonacci(n) << std::endl; -- GitLab