forked from ratanparai/cpp-template
-
Notifications
You must be signed in to change notification settings - Fork 92
/
cpplib_test.cc
54 lines (42 loc) · 1.33 KB
/
cpplib_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "src/lib/cpplib.h"
#include <map>
#include <vector>
#include "gtest/gtest.h"
TEST(CPPLibTest, ReturnHelloWorld) {
CPPLib cpplib;
std::string actual = cpplib.PrintHelloWorld();
std::string expected = "**** Hello World ****";
EXPECT_EQ(expected, actual);
}
TEST(CPPLibTest, CalculateFibonacci) {
CPPLib cpplib;
EXPECT_EQ(cpplib.fib(1), 1) << "Error: The factorial calculation was wrong!";
EXPECT_EQ(cpplib.fib(5), 5) << "Error: The factorial calculation was wrong!";
EXPECT_EQ(cpplib.fib(6), 8) << "Error: The factorial calculation was wrong!";
}
TEST(CPPLibTest, CalculateFibonacci2) {
CPPLib cpplib;
std::vector<int> inputs = {1, 2, 3, 4, 5, 6};
std::vector<int> actual;
for (auto &in : inputs) {
actual.push_back(cpplib.fib(in));
}
std::vector<int> expected = {1, 1, 2, 3, 5, 8};
EXPECT_EQ(expected, actual) << "Error: The factorial calculation was wrong!";
}
TEST(CPPLibTest, FindMaxHandlesSizeOne) {
CPPLib cpplib;
std::vector<int> inputs = {2};
EXPECT_EQ(cpplib.FindMax(inputs), 2);
// other stuff
}
TEST(CPPLibTest, FindMaxHandlesConsecutiveNumbers) {
CPPLib cpplib;
std::vector<int> inputs = {1, 2, 3, 4};
EXPECT_EQ(cpplib.FindMax(inputs), 4);
}
TEST(CPPLibTest, FindMaxHandlesEmptyVector) {
CPPLib cpplib;
std::vector<int> inputs = {};
EXPECT_EQ(cpplib.FindMax(inputs), -1);
}