-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcjb2953-TestVoting.c++
156 lines (131 loc) · 3.52 KB
/
cjb2953-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
//includes
#include <cassert> // assert
#include <iostream> // endl, istream, ostream
#include <iterator>
#include <sstream>
#include <vector>
#include <algorithm>
#include "gtest/gtest.h"
#include "Voting.h"
// -----
// print
// -----
TEST(Voting, print) {
std::ostringstream w;
string names [maxcandidates];
names[0] = "Hello";
voting_print(w, names);
ASSERT_TRUE(w.str() == "Hello\n");}
TEST(Voting, print2) {
std::ostringstream w;
string names [maxcandidates];
names[0] = "Carl Bai";
voting_print(w, names);
ASSERT_TRUE(w.str() == "Carl Bai\n");}
TEST(Voting, print3) {
std::ostringstream w;
string names [maxcandidates];
names[0] = "";
voting_print(w, names);
ASSERT_TRUE(w.str() == "");}
TEST(Voting, print4) {
std::ostringstream w;
string names [maxcandidates];
names[0] = " ";
voting_print(w, names);
ASSERT_TRUE(w.str() == " \n");}
//isLoser
TEST(Voting, isloser)
{
int numberofvotes[maxcandidates];
numberofvotes[0] = 1;
int loservote = 1;
int losers[maxcandidates];
losers[0] = 21;
isloser(numberofvotes, loservote, losers);
ASSERT_TRUE(numberofvotes[0] == 1);
}
TEST(Voting, isloser2)
{
int numberofvotes[maxcandidates];
numberofvotes[0] = 1;
int loservote = 1;
int losers[maxcandidates];
losers[0] = 21;
isloser(numberofvotes, loservote, losers);
ASSERT_TRUE(loservote == 1);
}
TEST(Voting, isloser3)
{
int numberofvotes[maxcandidates];
numberofvotes[0] = 1;
int loservote = 1;
int losers[maxcandidates];
losers[0] = 21;
isloser(numberofvotes, loservote, losers);
ASSERT_TRUE(losers[0] == 21);
}
TEST(Voting, solve) {
std::istringstream r("1\n\n1\nCarl Bai");
std::ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "Carl Bai\n");}
TEST(Voting, solve2) {
std::istringstream r("1\n\n2\nCarl Bai\nNavin Ratnayake\n");
std::ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "Carl Bai\nNavin Ratnayake\n");}
TEST(Voting, solve3) {
std::istringstream r("1\n\n2\nCarl Bai\nNavin Ratnayake\n2 1\n");
std::ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "Navin Ratnayake\n");}
TEST(Voting, solve4) {
std::istringstream r("1\n\n2\nCarl Bai\nNavin Ratnayake\n1 2\n");
std::ostringstream w;
voting_solve(r, w);
ASSERT_TRUE(w.str() == "Carl Bai\n");}
TEST(Voting, read)
{
std::istringstream r;
string arg[maxcandidates];
vector < vector< vector<int> > >vec;
vec = vector<vector<vector<int> > > (20);
int num_candidates = 10;
int num_votes = 0;
voting_read_candidates(r, arg, vec, num_candidates, &num_votes);
ASSERT_TRUE(num_candidates == 10);
}
TEST(Voting, read2)
{
std::istringstream r("Carl Bai");
string arg[maxcandidates];
vector < vector< vector<int> > >vec;
vec = vector<vector<vector<int> > > (20);
int num_candidates = 10;
int num_votes = 5;
voting_read_candidates(r, arg, vec, num_candidates, &num_votes);
ASSERT_TRUE(arg[0] == ("Carl Bai"));
}
TEST(Voting, read3)
{
std::istringstream r("Carl Bai\nNavin Ratnayake");
string arg[maxcandidates];
vector < vector< vector<int> > >vec;
vec = vector<vector<vector<int> > > (20);
int num_candidates = 10;
int num_votes = 5;
voting_read_candidates(r, arg, vec, num_candidates, &num_votes);
ASSERT_TRUE(arg[0] == ("Carl Bai"));
}
TEST(Voting, read4)
{
std::istringstream r("Carl Bai\nNavin Ratnayake");
string arg[maxcandidates];
vector < vector< vector<int> > >vec;
vec = vector<vector<vector<int> > > (20);
int num_candidates = 10;
int num_votes = 5;
voting_read_candidates(r, arg, vec, num_candidates, &num_votes);
ASSERT_TRUE(arg[1] == ("Navin Ratnayake"));
}