-
Notifications
You must be signed in to change notification settings - Fork 0
/
CThesaurusTest.cpp
121 lines (90 loc) · 4.82 KB
/
CThesaurusTest.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "common.cpp"
static void
AssertVectorsEqualCheck(std::vector<std::string>* A, std::vector<std::string> B, const char* File, int Line, const char* AExpr, const char* BExpr)
{
std::set<std::string> AA = {A->begin(), A->end()};
std::set<std::string> BB = {B.begin(), B.end()};
if(A->size() != B.size() ||
AA != BB)
{
fprintf(stderr, "Assert failed at %s:%d - Vectors '%s' and '%s' are not equal\n", File, Line, AExpr, BExpr);
for(std::string& Item : *A)
{
fprintf(stderr, "\"%s\", ", Item.c_str());
}
fprintf(stderr, "\n... comparing to ...\n");
for(std::string& Item : B)
{
fprintf(stderr, "\"%s\", ", Item.c_str());
}
fprintf(stderr, "\n");
exit(-1);
}
}
#define AssertVectorsEqual(A, B) AssertVectorsEqualCheck(A, B, __FILE__, __LINE__, #A, #B)
int main(int Argc, char** Argv)
{
{
CThesaurus Thesaurus;
Assert(Thesaurus.GetAllWords()->empty());
Assert(!Thesaurus.GetSynonyms("good"));
Assert(!Thesaurus.GetSynonyms("great"));
Assert(!Thesaurus.GetSynonyms("fabolous"));
}
{
CThesaurus Thesaurus;
std::vector<std::string> Synonyms = {"good", "great", "fabolous"};
Thesaurus.AddSynonyms(&Synonyms);
AssertVectorsEqual(Thesaurus.GetAllWords(), std::vector<std::string>({"fabolous", "good", "great"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("good"), std::vector<std::string>({"fabolous", "great"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("great"), std::vector<std::string>({"fabolous", "good"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("fabolous"), std::vector<std::string>({"good", "great"}));
}
{
CThesaurus Thesaurus;
std::vector<std::string> Synonyms = {"good", "Good", "gOoD", "GOOD"};
Thesaurus.AddSynonyms(&Synonyms);
AssertVectorsEqual(Thesaurus.GetAllWords(), std::vector<std::string>({"good"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("good"), std::vector<std::string>());
AssertVectorsEqual(Thesaurus.GetSynonyms("Good"), std::vector<std::string>());
AssertVectorsEqual(Thesaurus.GetSynonyms("gOoD"), std::vector<std::string>());
AssertVectorsEqual(Thesaurus.GetSynonyms("GOOD"), std::vector<std::string>());
}
{
CThesaurus Thesaurus;
std::vector<std::string> Synonyms = {"good", "great", "fabolous", "good", "fabolous", "great"};
Thesaurus.AddSynonyms(&Synonyms);
AssertVectorsEqual(Thesaurus.GetAllWords(), std::vector<std::string>({"fabolous", "good", "great"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("good"), std::vector<std::string>({"fabolous", "great"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("great"), std::vector<std::string>({"fabolous", "good"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("fabolous"), std::vector<std::string>({"good", "great"}));
}
{
CThesaurus Thesaurus;
std::vector<std::string> SynonymsA = {"good", "great", "fabolous"};
std::vector<std::string> SynonymsB = {"good", "great", "fabolous"};
Thesaurus.AddSynonyms(&SynonymsA);
Thesaurus.AddSynonyms(&SynonymsB);
AssertVectorsEqual(Thesaurus.GetAllWords(), std::vector<std::string>({"fabolous", "good", "great"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("good"), std::vector<std::string>({"fabolous", "great"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("great"), std::vector<std::string>({"fabolous", "good"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("fabolous"), std::vector<std::string>({"good", "great"}));
}
{
CThesaurus Thesaurus;
std::vector<std::string> SynonymsA = {"good", "great", "fabolous"};
std::vector<std::string> SynonymsB = {"nice", "extra", "excellent"};
std::vector<std::string> SynonymsC = {"good", "nice"};
Thesaurus.AddSynonyms(&SynonymsA);
Thesaurus.AddSynonyms(&SynonymsB);
Thesaurus.AddSynonyms(&SynonymsC);
AssertVectorsEqual(Thesaurus.GetAllWords(), std::vector<std::string>({"excellent", "extra", "fabolous", "good", "great", "nice"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("good"), std::vector<std::string>({"great", "fabolous", "nice"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("great"), std::vector<std::string>({"fabolous", "good"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("fabolous"), std::vector<std::string>({"good", "great"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("nice"), std::vector<std::string>({"extra", "excellent", "good"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("extra"), std::vector<std::string>({"excellent", "nice"}));
AssertVectorsEqual(Thesaurus.GetSynonyms("excellent"), std::vector<std::string>({"nice", "extra"}));
}
puts("Test passed");
}