-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_example_functions.cpp
57 lines (51 loc) · 2.23 KB
/
test_example_functions.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
#include "test_example_functions.h"
#include "log_duration.h"
using namespace std;
using namespace std::literals::string_literals;
void PrintDocument(const Document& document) {
cout << "{ "s
<< "document_id = "s << document.id << ", "s
<< "relevance = "s << document.relevance << ", "s
<< "rating = "s << document.rating << " }"s << endl;
}
void PrintMatchDocumentResult(int document_id, const vector<string_view>& words, DocumentStatus status) {
cout << "{ "s
<< "document_id = "s << document_id << ", "s
<< "status = "s << static_cast<int>(status) << ", "s
<< "words ="s;
for (const auto& word : words) {
cout << ' ' << word;
}
cout << "}"s << endl;
}
void AddDocument(SearchServer& search_server, int document_id, const string& document, DocumentStatus status,
const vector<int>& ratings) {
try {
search_server.AddDocument(document_id, document, status, ratings);
} catch (const invalid_argument& e) {
cout << "Ошибка добавления документа "s << document_id << ": "s << e.what() << endl;
}
}
void FindTopDocuments(const SearchServer& search_server, const string& raw_query) {
cout << "Результаты поиска по запросу: "s << raw_query << endl;
try {
LOG_DURATION_STREAM("Operation time"s, std::cout);
for (const Document& document : search_server.FindTopDocuments(raw_query)) {
PrintDocument(document);
}
} catch (const invalid_argument& e) {
cout << "Ошибка поиска: "s << e.what() << endl;
}
}
void MatchDocuments(const SearchServer& search_server, const string& query) {
try {
cout << "Матчинг документов по запросу: "s << query << endl;
LOG_DURATION_STREAM("Operation time"s, std::cout);
for (const int document_id: search_server) {
const auto [words, status] = search_server.MatchDocument(query, document_id);
PrintMatchDocumentResult(document_id, words, status);
}
} catch (const invalid_argument& e) {
cout << "Ошибка матчинга документов на запрос "s << query << ": "s << e.what() << endl;
}
}