-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.cpp
More file actions
182 lines (171 loc) · 6.17 KB
/
test_main.cpp
File metadata and controls
182 lines (171 loc) · 6.17 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
//
// Created by user on 19.02.2023.
//
#include <iostream>
#include "gtest/gtest.h"
#include "InvertedIndex.h"
#include "SearchServer.h"
typedef std::list<std::pair<std::string, float>> listAnswer;
/** Перед запуском тестов необходимо выбрать конфигурацию 'TEST'
* */
using namespace std;
void TestInvertedIndexFunctionality(
const vector<string>& docs,
const vector<string>& requests,
const vector<inverted_index::mapEntry>& expected) {
using namespace inverted_index;
vector<inverted_index::mapEntry> result;
InvertedIndex::getInstance().updateDocumentBase(docs);
for(const auto& request : requests) {
inverted_index::mapEntry word_count = InvertedIndex::getInstance().getWordCount(request);
result.push_back(word_count);
}
ASSERT_EQ(result, expected);
}
TEST(TestInvertedIndexFunctionality, TestBasic1) {
const vector<string> docs = {
"london is !the capital of great britain",
"big ben is the nickname for !the! Great bell the? of the striking clock"
};
const vector<string> requests = {"london", "the"};
const vector<inverted_index::mapEntry> expected = {
{
{0, 1}
}, {{
0, 1}, {1, 4}
}
};
TestInvertedIndexFunctionality(docs, requests, expected);
}
TEST(TestCaseInvertedIndex, TestBasic2) {
const vector<string> docs = {
"milk milk milk milk water water water",
"milk water water",
"milk milk milk milk milk water water water water water",
"americano cappuccino"
};
const vector<string> requests = {"milk", "water", "cappuccino"};
const vector<inverted_index::mapEntry> expected = {
{
{0, 4}, {1, 1}, {2, 5}
}, {
{0, 3}, {1, 2}, {2, 5}
}, {
{3, 1}
}
};
TestInvertedIndexFunctionality(docs, requests, expected);
}
TEST(TestCaseInvertedIndex, TestInvertedIndexMissingWord) {
const vector<string> docs = {
"a b c d e f g h i j k l",
"statement"
};
const vector<string> requests = {"m", "statement"};
const vector<inverted_index::mapEntry> expected = {
{
}, {
{1, 1}
}
};
TestInvertedIndexFunctionality(docs, requests, expected);
}
TEST(TestCaseSearchServer, TestTop5) {
const vector<string> docs = {
"london is the capital of great britain",
"paris is the capital of france",
"berlin is the capital of germany",
"rome is the capital of italy",
"madrid is the capital of spain",
"lisboa is the capital of portugal",
"bern is the capital of switzerland",
"moscow is the capital of russia",
"kiev is the capital of ukraine",
"minsk is the capital of belarus",
"astana is the capital of kazakhstan",
"beijing is the capital of china",
"tokyo is the capital of japan",
"bangkok is the capital of thailand",
"welcome to moscow the capital of russia the third rome",
"amsterdam is the capital of netherlands",
"helsinki is the capital of finland",
"oslo is the capital of norway",
"stockholm is the capital of sweden",
"riga is the capital of latvia",
"tallinn is the capital of estonia",
"warsaw is the capital of poland",
};
string request = {"moscow is the capital of russia"};
const listAnswer expected = {
{
{"7", 1},
{"14", 1},
{"0", 0.666666687},
{"1", 0.666666687},
{"2", 0.666666687}
}
};
search_server::SearchServer srv(docs, false);
listAnswer result = srv.getAnswer(request);
ASSERT_EQ(result, expected);
}
TEST(TestCaseSearchServer, TestTop5_MissingWord) {
const vector<string> docs = {
"Moscow is my favorite city, also Moscow is the capital of Russia",
"berlin is the capital of germany",
"I was born in Moscow",
"I from Russia",
"A capital is main city in any country",
"moscow is the capital of russia!",
};
string request = {"moscow is the capital of russia MissingWord"};
const listAnswer expected = {
{"0", 1},
{"5", 0.75},
{"1", 0.5},
{"4", 0.25},
{"2", 0.125}
};
search_server::SearchServer srv(docs, false);
listAnswer result = srv.getAnswer(request);
ASSERT_EQ(result, expected);
}
TEST(TestCaseSearchServer, TestTop5_Extact_Search) {
const vector<string> docs = {
"Moscow is my favorite city, also Moscow is the capital of Russia",
"berlin is the capital of germany",
"I was born in Moscow",
"I from Russia",
"A capital is main city in any country",
"moscow is the capital of russia",
};
string request = {"moscow is the capital of Russia"};
const listAnswer expected = {
{
{"0", 1},
{"5", 0.75}
}
};
search_server::SearchServer srv(docs, true);
listAnswer result = srv.getAnswer(request);
ASSERT_EQ(result, expected);
}
TEST(TestCaseSearchServer, TestTop5_Extact_Search_MissingWord) {
const vector<string> docs = {
"Moscow is my favorite city, also Moscow is the capital of Russia",
"berlin is the capital of germany",
"I was born in Moscow",
"I from Russia",
"A capital is main city in any country",
"moscow is the capital of russia",
};
string request = {"moscow is the capital of Russia MissingWord"};
const listAnswer expected = {};
search_server::SearchServer srv(docs, true);
listAnswer result = srv.getAnswer(request);
ASSERT_EQ(result, expected);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}