-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheayivi-TestVoting.c++
233 lines (172 loc) · 6.22 KB
/
eayivi-TestVoting.c++
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* TestVoting.c++
*
*/
/*
To Test the program:
% g++ -pedantic -std=c++0x -Wall Voting.c++ TestVoting.c++ -o TestVoting -lgtest -lpthread -lgtest_main
% valgrind TestVoting > TestVoting.out
*/
// includes
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include "gtest/gtest.h"
#include "Voting.h"
using namespace std;
// read
TEST(Voting, read_0) {
//string ex = "1\n\n2\nRene Trevino\nEnam\n1 2\n1 2\n2 1\n";
//!! Above line breaks, because voting_read cannot handle election count (unlike voting_solve)
string ex = "2\nRene Trevino\nEnam\n1 2\n1 2\n2 1\n";
std::istringstream r(ex);
string names [20];
vector<deque<int>> vect(5);
//int tcnt = 0; as above, cannot measure elections_counts with voting_read :)
int ccnt = 0;
int vcnt = 0;
bool v = voting_read(r, vcnt, ccnt, names, vect);
ASSERT_TRUE(v == true);
ASSERT_TRUE(vcnt == 3);
ASSERT_TRUE(ccnt == 2);
}
TEST(Voting, read_1) {
string ex = "3\nJohn Doe\nJane Smith\nSirhan Sirhan\n1 2 3\n2 1 3\n2 3 1\n1 2 3\n3 1 2\n";
std::istringstream r(ex);
string names [20];
vector<deque<int>> vect(30);
int ccnt = 0;
int vcnt = 0;
bool v = voting_read(r, vcnt, ccnt, names, vect);
ASSERT_TRUE(v == true);
ASSERT_TRUE(ccnt == 3);
ASSERT_TRUE(vcnt == 5);
}
TEST(Voting, read_2) {
string ex = "3\nJohn Doe\nJane Smith\nSirhan Sirhan\n1 2 3\n2 1 3\n2 3 1\n1 2 3\n3 1 2\n";
std::istringstream r2(ex);
string s [20];
vector<deque<int>> vect(5);
int ccnt = 7;
int vcnt = 9;
bool v1 = voting_read(r2, vcnt, ccnt, s, vect);
ASSERT_TRUE(v1 == true);
ASSERT_TRUE(vcnt == 5);
ASSERT_TRUE(ccnt == 3);
}
TEST(Voting, read_3) {
string ex = "4\nJohn Doe\nJane Smith\nAizhuldyz G\nSirhan Sirhan\n1 2 3\n2 1 3\n2 3 1\n1 2 3\n3 1 2\n";
std::istringstream r2(ex);
string s [20];
vector<deque<int>> vect(5);
int ccnt = 17;
int vcnt = 99;
bool v1 = voting_read(r2, vcnt, ccnt, s, vect);
ASSERT_TRUE(v1 == true);
ASSERT_TRUE(vcnt == 5);
ASSERT_TRUE(ccnt == 4);
}
TEST(Voting, read_4) {
string ex = "3\nGlenn Downing\nJane Smith\nSirhan Sirhan\n1 2 3\n2 1 3\n2 3 1\n1 2 3\n3 1 2\n";
std::istringstream r2(ex);
string s [20];
vector<deque<int>> vect(5);
int ccnt = -2;
int vcnt = -8;
bool v1 = voting_read(r2, vcnt, ccnt, s, vect);
ASSERT_TRUE(v1 == true);
ASSERT_TRUE(vcnt == 5);
ASSERT_TRUE(ccnt == 3);
}
TEST(Voting, read_5) {
string ex = "3\nMiley Cirus\nWill Smith\nRobin Thicke\n1 2 3\n2 1 3\n2 3 1\n1 2 3\n3 1 2\n";
std::istringstream r2(ex);
string s [20];
vector<deque<int>> vect(5);
int ccnt = 7;
int vcnt = 9;
bool v1 = voting_read(r2, vcnt, ccnt, s, vect);
ASSERT_TRUE(v1 == true);
ASSERT_TRUE(vcnt == 5);
ASSERT_TRUE(ccnt == 3);
}
TEST(Voting, solve_0) {
istringstream r("1\n\n3\nJohn Smith\nJane Doe\nJack Shepard\n1 2 3\n1 2 3\n1 3 2\n1 2 3\n1 3 2\n1 2 3\n");
ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "John Smith\n");
}
TEST(Voting, solve_1) {
istringstream r("1\n\n3\nJohn Smith\nJane Doe\nJack Shepard\n2 1 3\n1 2 3\n1 3 2\n1 2 3\n1 3 2\n1 2 3\n");
ostringstream w;
voting_solve(r,w);
ASSERT_TRUE(w.str() == "John Smith\n");
}
TEST(Voting, solve_2) {
istringstream r("1\n\n3\nJohn Smith\nJane Doe\nJack Shepard\n1 2 3\n1 2 3\n1 3 2\n1 2 3\n1 3 2\n1 2 3\n");
ostringstream w;
voting_solve(r,w);
ASSERT_TRUE(w.str() == "John Smith\n");
}
TEST(Voting, solve_3)
{
istringstream r("1\n\n1\na\n1\n");
ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "a\n");
}
TEST(Voting, solve_4)
{
istringstream r("1\n\n2\na\nb\n1 2\n2 1\n");
ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "a\nb\n");
}
TEST(Voting, solve_multiple_elections)
{
istringstream r("2\n\n1\na\n1\n\n2\na\nb\n1 2\n2 1\n");
ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "a\n\na\nb\n");
}
TEST(Voting, voting_solve_normal) {
istringstream r("1\n\n3\nJohn Doe\nJane Smith\nSirhan Sirhan\n1 2 3\n1 2 3\n1 2 3\n1 2 3\n3 1 2\n");
ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "John Doe\n");
}
TEST(Voting, voting_solve_recount) {
istringstream r("1\n\n3\nJohn Doe\nJane Smith\nSirhan Sirhan\n1 2 3\n2 1 3\n2 3 1\n1 2 3\n3 1 2\n");
ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "John Doe\n");
}
TEST(Voting, voting_solve_tie) {
istringstream r("1\n\n3\nJohn Doe\nJane Smith\nSirhan Sirhan\n1 2 3\n1 2 3\n2 1 3\n2 1 3\n3 1 2\n3 2 1\n");
ostringstream w;
voting_solve(r, w);
// cout << w.str();
ASSERT_TRUE(w.str() == "John Doe\nJane Smith\nSirhan Sirhan\n");
}
TEST(Voting, voting_solve_two_vote) {
istringstream r("1\n\n7\nBarack Obama\nyou\nJim Carey\nJake Gellenhall\nMariah Carey\nJim\ngucci\n2 6 1 5 3 7 4\n6 7 2 4 5 3 1\n");
ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "you\nJim\n");
}
TEST(Voting, voting_solve_long_case) {
istringstream r("1\n\n10\nyou\nJim\ngucci\nHillary Clinton\nGlenn Downing\nMadonna\nMariah Carey\ncandidate0\nJim Carey\nJake Gellenhall\n4 6 9 1 7 5 3 2 8 10\n3 4 9 5 1 10 7 6 2 8\n9 4 8 1 3 2 7 6 5 10\n9 2 4 3 1 5 6 7 8 10\n2 8 4 5 10 9 7 6 1 3\n8 2 4 9 3 10 7 6 1 5\n1 6 5 9 4 8 7 2 3 10\n7 6 4 8 1 3 10 9 5 2\n5 1 8 9 4 7 10 2 6 3\n6 10 8 4 1 3 2 9 5 7\n7 10 1 3 6 4 8 5 2 9\n6 10 5 1 3 2 7 8 9 4\n7 4 9 10 8 5 1 2 3 6\n10 9 2 7 8 5 3 6 1 4\n9 6 4 2 3 10 8 1 5 7\n2 10 4 8 6 3 9 5 1 7\n1 6 5 4 3 10 7 2 8 9\n1 7 6 3 4 9 8 10 5 2\n");
ostringstream w;
voting_solve(r, w);
// cout << w.str();
ASSERT_TRUE(w.str() == "Jim Carey\n");
}
TEST(Voting, voting_solve_another_long_case) {
istringstream r("1\n\n8\nyou\nGlenn Downing\nJim Carey\ncandidate0\ngucci\nJake Gellenhall\nHillary Clinton\nBarack Obama\n3 2 8 7 6 4 5 1\n7 2 1 3 4 5 6 8\n5 3 2 8 1 7 4 6\n4 2 8 5 7 6 1 3\n3 8 5 4 7 6 1 2\n8 6 2 7 5 3 4 1\n7 4 8 2 3 1 6 5\n8 1 3 7 5 4 2 6\n1 8 2 3 6 7 5 4\n6 5 2 8 4 3 7 1\n4 8 7 3 1 6 5 2\n2 3 5 1 7 4 8 6\n8 6 1 5 7 4 2 3\n7 8 5 2 3 4 1 6\n7 8 5 3 2 6 4 1\n");
ostringstream w;
voting_solve(r, w);
// cout << w.str();
ASSERT_TRUE(w.str() == "Barack Obama\n");
}