-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunit_test_basic.cpp
More file actions
217 lines (187 loc) · 8.77 KB
/
Copy pathunit_test_basic.cpp
File metadata and controls
217 lines (187 loc) · 8.77 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "unit_test_basic.h"
#include <vector>
#include <wsjcpp_core.h>
#include <wsjcpp_diff_text.h>
REGISTRY_WSJCPP_UNIT_TEST(UnitTestBasic)
UnitTestBasic::UnitTestBasic()
: WsjcppUnitTestBase("UnitTestBasic") {
}
// ---------------------------------------------------------------------
bool UnitTestBasic::doBeforeTest() {
// nothing
return true;
}
// ---------------------------------------------------------------------
void UnitTestBasic::executeTest() {
struct LTest {
LTest(
std::string txt1,
std::string txt2,
std::string txt3,
std::vector<WsjcppDiffTextRow> arr1,
std::vector<WsjcppDiffTextRow> arr2,
unsigned int n
) : txt1(txt1), txt2(txt2), txt3(txt3), arr1(arr1), arr2(arr2), n(n) {
//
}
std::string txt1;
std::string txt2;
std::string txt3;
std::vector<WsjcppDiffTextRow> arr1;
std::vector<WsjcppDiffTextRow> arr2;
unsigned int n;
};
std::vector<LTest *> tests1;
std::vector<WsjcppDiffTextRow> arr1, arr2;
std::string text1 = text001();
std::string text2 = text002();
// std::cout << text1.toStdString() << "\n";
//empty (Test №1)
tests1.push_back(new LTest("", "", "", arr1, arr2, 0));
//without any difference (Test №2)
tests1.push_back(new LTest("I\ngot\nMike", "I\ngot\nMike", "I\ngot\nMike", arr1, arr2, 0));
//with a difference in the ending (Tests №3-6)
tests1.push_back(new LTest("I\ngot\nMike", "I\ngot\nMike", "I\ngot\nNike", arr1, arr2, 1));
tests1.push_back(new LTest("I\ngot\nNike", "I\ngot\nMike", "I\ngot\nMike", arr1, arr2, 1));
tests1.push_back(new LTest("I\ngot\nNike", "I\ngot\nMike", "I\ngot\nNike", arr1, arr2, 1));
tests1.push_back(new LTest("I\ngot\nBike", "I\ngot\nMike", "I\ngot\nNike", arr1, arr2, 1));
//with a difference in the beginning (Tests №7-10)
tests1.push_back(new LTest("I\ngot\nMike", "I\ngot\nMike", "You\ngot\nMike", arr1, arr2, 1));
tests1.push_back(new LTest("You\ngot\nMike", "I\ngot\nMike", "I\ngot\nMike", arr1, arr2, 1));
tests1.push_back(new LTest("You\ngot\nMike", "I\ngot\nMike", "You\ngot\nMike", arr1, arr2, 1));
tests1.push_back(new LTest("We\ngot\nMike", "I\ngot\nMike", "You\ngot\nMike", arr1, arr2, 1));
//with a difference in the middle of the row (Tests №11-15)
tests1.push_back(new LTest("I\nhave\ncute\ncats", "I\nhave\ncute\ncats", "I\nhave\nhuge\ncats", arr1, arr2, 1));
tests1.push_back(new LTest("I\nhave\nhuge\ncats", "I\nhave\ncute\ncats", "I\nhave\ncute\ncats", arr1, arr2, 1));
tests1.push_back(new LTest("I\nhave\nhuge\ncats", "I\nhave\ncute\ncats", "I\nhave\nhuge\ncats", arr1, arr2, 1));
tests1.push_back(new LTest("I\nhave\ndifference\ncats", "I\nhave\ncute\ncats", "I\nhave\nhuge\ncats", arr1, arr2, 1));
tests1.push_back(new LTest("I\nbetray\ncats", "I\nhave\ncats", "I\nlove\ncats", arr1, arr2, 1));
//delete lines from the end of text (Tests №16-19)
tests1.push_back(new LTest("Go\nto\nthe\nschool", "Go\nto\nthe\nschool", "Go\nto", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto", "Go\nto\nthe\nschool", "Go\nto\nthe\nschool", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto\nthe", "Go\nto\nthe\nschool", "Go\nto", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto", "Go\nto\nthe\nschool", "Go\nto\nthe", arr1, arr2, 2));
//add lines in the end of text (Tests №20-23)
tests1.push_back(new LTest("Go\nto", "Go\nto", "Go\nto\nthe\nschool", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto\nthe\nschool", "Go\nto", "Go\nto", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto\nthe", "Go\nto", "Go\nto\nthe\nschool", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto\nthe\nschool", "Go\nto", "Go\nto\nthe", arr1, arr2, 2));
//delete rows from the beginning and the middle of text (Tests №24-27)
tests1.push_back(new LTest("Go\nto\nthe\nschool", "Go\nto\nthe\nschool", "the\nschool", arr1, arr2, 2));
tests1.push_back(new LTest("the\nschool", "Go\nto\nthe\nschool", "Go\nto\nthe\nschool", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto\nthe\nschool", "Go\nto\nthe\nschool", "Go\nto\nschool", arr1, arr2, 1));
tests1.push_back(new LTest("Go\nto\nschool", "Go\nto\nthe\nschool", "Go\nto\nthe\nschool", arr1, arr2, 1));
//add rows to the beginning and the middle of text (Tests №28-31)
tests1.push_back(new LTest("the\nschool", "the\nschool", "Go\nto\nthe\nschool", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nto\nthe\nschool", "the\nschool", "the\nschool", arr1, arr2, 2));
tests1.push_back(new LTest("Go\nthe\nschool", "the\nschool", "the\nschool", arr1, arr2, 1));
tests1.push_back(new LTest("the\nschool", "the\nschool", "Go\nthe\nschool", arr1, arr2, 1));
//complex (Tests №32-33)
tests1.push_back(new LTest("You\nare\ngot\nand\ngood", "I\ngot\nMike\nand\nthis is\ngood\nboy", "I\ncure\ndamn\nill\ncancer", arr1, arr2, 8));
tests1.push_back(new LTest("We\nspent\nthe rest\nof our life\non\nthis\ncourse\nwork", "We\nspent\na lot of\ntime\non\nthis\ncourse\nwork", "We\ngonna\nspend\na lot of\nfunky\ntime\non\ncourse\nwork", arr1, arr2, 6));
for (unsigned int i = 0; i < tests1.size(); i++) {
std::string txt1 = tests1[i]->txt1;
std::string txt2 = tests1[i]->txt2;
std::string txt3 = tests1[i]->txt3;
WsjcppDiffText::merge(txt1, txt2, txt3, arr1, arr2);
unsigned int n = tests1[i]->n;
compare("In the test №" + std::to_string(i + 1) + " the length of the vector is expected: "
+ std::to_string(n) + ", but obtained: " + std::to_string(arr1.size()),
arr1.size(), n);
arr1.clear(), arr2.clear();
}
//sort module test
struct LTest2 {
LTest2(
std::string txt1,
std::string txt2,
std::string txt3,
std::vector<WsjcppDiffTextRow> arr1,
std::vector<WsjcppDiffTextRow> arr2,
std::vector<WsjcppDiffTextRow> arr3
) : txt1(txt1), txt2(txt2), txt3(txt3), arr1(arr1), arr2(arr2), arr3(arr3) {
//
}
std::string txt1;
std::string txt2;
std::string txt3;
std::vector<WsjcppDiffTextRow> arr1;
std::vector<WsjcppDiffTextRow> arr2;
std::vector<WsjcppDiffTextRow> arr3;
};
std::vector<LTest2 *> tests2;
std::vector<WsjcppDiffTextRow> arr3;
int id[8] = {0,1,1,2,3,4,5,6};
std::vector<std::string> skey;
skey.push_back("I");
skey.push_back("got");
skey.push_back("!add");
skey.push_back("Mike");
skey.push_back("and");
skey.push_back("this is");
skey.push_back("!del");
skey.push_back("!del");
std::vector<std::string> sline;
sline.push_back("You");
sline.push_back("cure");
sline.push_back("are");
sline.push_back("damn");
sline.push_back("ill");
sline.push_back("cancer");
sline.push_back("good");
sline.push_back("boy");
for (int i = 0; i < skey.size(); ++i) {
arr3.push_back(WsjcppDiffTextRow(id[i], skey.at(i), sline.at(i)));
}
tests2.push_back(new LTest2(
"You\nare\ngot\nand\ngood",
"I\ngot\nMike\nand\nthis is\ngood\nboy",
"I\ncure\ndamn\nill\ncancer",
arr1, arr2, arr3));
std::string txt1 = tests2[0]->txt1;
std::string txt2 = tests2[0]->txt2;
std::string txt3 = tests2[0]->txt3;
WsjcppDiffText::merge(txt1, txt2, txt3, arr1, arr2);
for (int i = 0; i < 8; ++i) {
int id1 = arr1[i].getNumberOfLine();
int id2 = arr3[i].getNumberOfLine();
std::string key1 = arr1[i].getKey();
std::string key2 = arr3[i].getKey();
std::string line1 = arr1[i].getLine();
std::string line2 = arr3[i].getLine();
compare("In the sort test in the element №" + std::to_string(i+1) + ": id1 != id2", id1, id2);
compare("In the sort test in the element №" + std::to_string(i+1) + ": key1 != key2", key1, key2);
compare("In the sort test in the element №" + std::to_string(i+1) + ": line1 != line2", line1, line2);
}
}
// ---------------------------------------------------------------------
bool UnitTestBasic::doAfterTest() {
// nothing
return true;
}
// ---------------------------------------------------------------------
std::string UnitTestBasic::text001() {
return "Str1\n"
"Str\n"
"Str\n"
"Str\n"
"Str2\n"
"Str3\n"
"Str\n"
"Str\n"
"Str\n";
}
// ---------------------------------------------------------------------
std::string UnitTestBasic::text002() {
return "Str1\n"
"Str \n"
"Str\n"
"Str\n"
"Str2\n"
"Str\n"
"Str3\n"
"Str\n"
"Str\n"
"Str\n";
}
// ---------------------------------------------------------------------