s0509
This commit is contained in:
parent
ff53de285f
commit
59242266b3
13
include/s0509_fibonacci_number.hpp
Normal file
13
include/s0509_fibonacci_number.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef S0509_FIBONACCI_NUMBER_HPP
|
||||
#define S0509_FIBONACCI_NUMBER_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class S0509 {
|
||||
public:
|
||||
int fib(int n);
|
||||
};
|
||||
|
||||
#endif
|
9
src/s0509_fibonacci_number.cpp
Normal file
9
src/s0509_fibonacci_number.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "s0509_fibonacci_number.hpp"
|
||||
|
||||
int S0509::fib(int n) {
|
||||
vector<int> dp{0, 1};
|
||||
for (int i{2}; i <= n; ++i) {
|
||||
dp.push_back(dp[i - 1] + dp[i - 2]);
|
||||
}
|
||||
return dp[n];
|
||||
}
|
24
tests/s0509_fibonacci_number.cpp
Normal file
24
tests/s0509_fibonacci_number.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "s0509_fibonacci_number.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Problem509, Case1) {
|
||||
int n{2};
|
||||
int expected{1};
|
||||
S0509 solution;
|
||||
EXPECT_EQ(solution.fib(n), expected);
|
||||
}
|
||||
|
||||
TEST(Problem509, Case2) {
|
||||
int n{3};
|
||||
int expected{2};
|
||||
S0509 solution;
|
||||
EXPECT_EQ(solution.fib(n), expected);
|
||||
}
|
||||
|
||||
TEST(Problem509, Case3) {
|
||||
int n{4};
|
||||
int expected{3};
|
||||
S0509 solution;
|
||||
EXPECT_EQ(solution.fib(n), expected);
|
||||
}
|
Loading…
Reference in New Issue
Block a user