/
test.cpp
142 lines (106 loc) · 4.43 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
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
//
// Created by artyom on 13.02.16.
//
#include "gtest/gtest.h"
#include "count.h"
TEST(WordCountTest, ConstStringTest)
{
const char* text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
" Curabitur at sollicitudin risus. Proin id dictum ex. Cum sociis"
" natoque penatibus et magnis dis parturient montes, nascetur"
" ridiculus mus. Donec porta felis magna, eu fringilla sapien porta"
" consectetur. Vestibulum sagittis, dui sit amet sagittis posuere,"
" augue tellus mollis mauris, id ornare.";
auto counted = countWords(text, strlen(text));
auto flipped = flipMap<string, int>(counted);
int wordsTotal = 0;
for (auto it: flipped) {
wordsTotal += it.first;
}
ASSERT_EQ(wordsTotal, 50);
wordStatFlipped m = {{2, "amet"},
{2, "consectetur"},
{2, "id"}};
ASSERT_TRUE(std::equal(m.begin(), m.end(), flipped.rbegin()));
}
TEST(WordCountTest, FileTest)
{
pair<const char*, size_t> text = loadTextFromFile("book.txt");
auto counted = countWords(text.first, text.second);
auto flipped = flipMap<string, int>(counted);
wordStatFlipped m = {{20304, "и"},
{10198, "в"},
{8428, "не"},
{7822, "что"},
{6453, "на"}};
ASSERT_TRUE(std::equal(m.rbegin(), m.rend(), flipped.rbegin()));
}
TEST(WordCountBlockwiseTest, FileTest)
{
pair<const char*, size_t> text = loadTextFromFile("book.txt");
auto counted = countWordsBlockwise(text.first, text.second, defaultThreadCount);
auto flipped = flipMap<string, int>(counted);
wordStatFlipped m = {{20304, "и"},
{10198, "в"},
{8428, "не"},
{7822, "что"},
{6453, "на"}};
ASSERT_TRUE(std::equal(m.rbegin(), m.rend(), flipped.rbegin()));
}
TEST(WordCountBlockwiseTest, FileParAndSeqTest)
{
pair<const char*, size_t> text = loadTextFromFile("book.txt");
auto counted1 = countWords(text.first, text.second);
auto flipped1 = flipMap<string, int>(counted1);
auto counted2 = countWordsBlockwise(text.first, text.second, defaultThreadCount);
auto flipped2 = flipMap<string, int>(counted2);
ASSERT_TRUE(std::equal(flipped1.rbegin(), flipped1.rend(), flipped2.rbegin()));
}
#ifdef WITH_OPENMP
TEST(WordCountOpenMPTest, FileTest)
{
pair<const char*, size_t> text = loadTextFromFile("book.txt");
auto counted = countWordsOpenMP(text.first, text.second, defaultThreadCount);
auto flipped = flipMap<string, int>(counted);
wordStatFlipped m = {{20304, "и"},
{10198, "в"},
{8428, "не"},
{7822, "что"},
{6453, "на"}};
ASSERT_TRUE(std::equal(m.rbegin(), m.rend(), flipped.rbegin()));
}
TEST(WordCountOpenMPTest, FileParAndSeqTest)
{
pair<const char*, size_t> text = loadTextFromFile("book.txt");
auto counted1 = countWords(text.first, text.second);
auto flipped1 = flipMap<string, int>(counted1);
auto counted2 = countWordsOpenMP(text.first, text.second, defaultThreadCount);
auto flipped2 = flipMap<string, int>(counted2);
ASSERT_TRUE(std::equal(flipped1.rbegin(), flipped1.rend(), flipped2.rbegin()));
}
#endif
TEST(WordCountPthreadsTest, FileTest)
{
pair<const char*, size_t> text = loadTextFromFile("book.txt");
auto counted = countWordsPthreads(text.first, text.second, defaultThreadCount);
auto flipped = flipMap<string, int>(counted);
wordStatFlipped m = {{20304, "и"},
{10198, "в"},
{8428, "не"},
{7822, "что"},
{6453, "на"}};
ASSERT_TRUE(std::equal(m.rbegin(), m.rend(), flipped.rbegin()));
}
TEST(WordCountPthreadsTest, FileParAndSeqTest)
{
pair<const char*, size_t> text = loadTextFromFile("book.txt");
auto counted1 = countWords(text.first, text.second);
auto flipped1 = flipMap<string, int>(counted1);
auto counted2 = countWordsPthreads(text.first, text.second, defaultThreadCount);
auto flipped2 = flipMap<string, int>(counted2);
ASSERT_TRUE(std::equal(flipped1.rbegin(), flipped1.rend(), flipped2.rbegin()));
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}