-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
72 lines (63 loc) · 2.29 KB
/
test.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "gtest/gtest.h"
#include "solution.h"
class SolutionTest : public ::testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
// Code here will be called immediately after each test
// (right before the destructor).
}
};
TEST_F(SolutionTest,testEmptyGetPhoneBook) {
Solution solution;
std::map<std::string,int> phoneBook;
phoneBook = solution.getPhoneBook();
ASSERT_EQ(true,phoneBook.empty());
}
TEST_F(SolutionTest,testOneEntryGetPhoneBookIsNotEmpty) {
Solution solution;
std::map<std::string,int> phoneBook;
solution.setPhoneBook("sam", 99912222);
phoneBook = solution.getPhoneBook();
ASSERT_EQ(false,phoneBook.empty());
}
TEST_F(SolutionTest,testEmptyMapNotFoundEntySearchPhonebook) {
Solution solution;
std::map<std::string,int> phoneBook;
phoneBook = solution.getPhoneBook();
ASSERT_EQ(true,phoneBook.empty());
ASSERT_EQ("Not found\n", solution.searchPhoneBook("sam"));
}
TEST_F(SolutionTest,testPopulatedMapNotFoundEntySearchPhonebook) {
Solution solution;
std::map<std::string,int> phoneBook;
solution.setPhoneBook("sam", 99912222);
phoneBook = solution.getPhoneBook();
ASSERT_EQ(false,phoneBook.empty());
ASSERT_EQ("Not found\n", solution.searchPhoneBook("invalid"));
}
TEST_F(SolutionTest,testPopulatedMapValidEntrySearchPhonebook) {
Solution solution;
std::map<std::string,int> phoneBook;
solution.setPhoneBook("sam", 99912222);
phoneBook = solution.getPhoneBook();
ASSERT_EQ(false,phoneBook.empty());
ASSERT_EQ("sam=99912222\n", solution.searchPhoneBook("sam"));
}
TEST_F(SolutionTest,testPopulatedMapiMultipleValidEntrySearchPhonebook) {
Solution solution;
std::map<std::string,int> phoneBook;
solution.setPhoneBook("sam", 99912222);
solution.setPhoneBook("tom", 11122222);
solution.setPhoneBook("harry", 12299933);
phoneBook = solution.getPhoneBook();
ASSERT_EQ(false,phoneBook.empty());
ASSERT_EQ("sam=99912222\n", solution.searchPhoneBook("sam"));
ASSERT_EQ("tom=11122222\n", solution.searchPhoneBook("tom"));
ASSERT_EQ("harry=12299933\n", solution.searchPhoneBook("harry"));
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}