-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathballot_test.go
40 lines (35 loc) · 994 Bytes
/
ballot_test.go
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
package main
import "testing"
func TestFindWinner(t *testing.T) {
testCases:=[]struct{
candidateName []string
winner string
}{
{[]string{"a"},"a"},
{[]string{"a","b","b","a","A","c","C","C"},"c"},
{[]string{},""},
}
for _,testCase:=range testCases{
actualWinner:=FindWinner(testCase.candidateName)
if actualWinner!=testCase.winner{
t.Errorf("FindWinner didn't return the correct winner - expected %v, got %v",testCase.winner,actualWinner)
}
}
}
func TestFindWinnerV2(t *testing.T) {
testData:=make([]Ballot,0,0)
testData=append(testData,Ballot{[]string{"c","a","a"}})
testData=append(testData,Ballot{[]string{"c","a","a"}})
testCases:=[]struct{
candidateName []Ballot
winner string
}{
{testData,"a"},
}
for _,testCase:=range testCases{
actualWinner:=FindWinnerV2(testCase.candidateName,false)
if actualWinner!=testCase.winner{
t.Errorf("FindWinner didn't return the correct winner - expected %v, got %v",testCase.winner,actualWinner)
}
}
}