-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestVoting.py
124 lines (77 loc) · 2.91 KB
/
TestVoting.py
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
from io import StringIO
from unittest import main,TestCase
from Voting import voting_solve,has_winner,Candidate,Ballot
class TestVoting(TestCase):
def test_has_winner_1(self):
candi = Candidate("candi")
candi_2 = Candidate("candi_2")
list_1 = [candi, candi_2]
a = has_winner(3, 2.5, list_1)
self.assertEqual(a, True)
def test_has_winner_2(self):
a = has_winner(1, .25, ["Red", "Green", "Blue", "Orange"])
self.assertEqual(a, True)
def test_has_winner_3(self):
a = has_winner(9, 2, ["C1", "C2", "C3", "C4"])
self.assertEqual(a, True)
def test_has_winner_4(self):
a = has_winner(5, 2, ["1", "2", "3"])
self.assertEqual(a, False)
def test_Candidate_class1(self):
p = Candidate("a")
self.assertEqual(p.name, "a")
self.assertEqual(p.count,0)
self.assertEqual(p.ballot_list,[])
def test_Candidate_class2(self):
p = Candidate("b")
self.assertEqual(p.name, "b")
self.assertEqual(p.count,0)
self.assertEqual(p.ballot_list,[])
def test_Candidate_class3(self):
p = Candidate("c")
self.assertEqual(p.name, "c")
self.assertEqual(p.count,0)
self.assertEqual(p.ballot_list,[])
# below are test for ballot class
def test_Ballot_class1(self):
ballot = Ballot([1,2,3])
self.assertEqual(ballot.get_next(1),2)
def test_Ballot_class2(self):
ballot = Ballot([1,2,3])
self.assertEqual(ballot.get_next(0),1)
def test_Ballot_class3(self):
ballot = Ballot([1,2,3])
self.assertEqual(ballot.get_next(2),3)
def test_Ballot_class4(self):
ballot = Ballot([5,6,7])
self.assertEqual(ballot.get_next(0),5)
def test_Ballot_class5(self):
ballot = Ballot([5,6,7])
self.assertEqual(ballot.get_next(1),6)
def test_Ballot_class6(self):
ballot = Ballot([5,6,7])
self.assertEqual(ballot.get_next(2),7)
def test_haswinner1(self):
self.assertEqual(has_winner(5, 1, [Candidate("a")]),True)
def test_haswinner2(self):
self.assertEqual(has_winner(4, 1, [Candidate("b")]),True)
def test_haswinner3(self):
self.assertEqual(has_winner(3, 1, [Candidate("c")]),True)
def test_haswinner4(self):
self.assertEqual(has_winner(7, 1, [Candidate("d")]),True)
def test_haswinner5(self):
self.assertEqual(has_winner(8, 1, [Candidate("e")]),True)
def test_votingsolve(self):
jo = Candidate("jo")
ja = Candidate("ja")
r = StringIO("1\n\n2\nJo\nJa\n2 1\n2 1")
w = StringIO()
self.assertEqual(voting_solve(r,w),None)
def test_votingsolve1(self):
jo = Candidate("jo")
ja = Candidate("ja")
Ss = Candidate("Ss")
r = StringIO("1\n\n3\nJo\nJa\nSs\n1 2 3\n2 1 3\n2 3 1\n1 2 3\n3 1 2")
w = StringIO()
self.assertEqual(voting_solve(r,w),None)
main()