-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathq1_test.go
59 lines (54 loc) · 1.09 KB
/
q1_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cos418_hw1_1
import (
"fmt"
"testing"
)
func equal(counts1, counts2 []WordCount) bool {
if len(counts1) != len(counts2) {
return false
}
for i := range counts1 {
if counts1[i] != counts2[i] {
return false
}
}
return true
}
func assertEqual(t *testing.T, answer, expected []WordCount) {
if !equal(answer, expected) {
t.Fatal(fmt.Sprintf(
"Word counts did not match...\nExpected: %v\nActual: %v",
expected,
answer))
}
}
func TestSimple(t *testing.T) {
answer1 := topWords("simple.txt", 4, 0)
answer2 := topWords("simple.txt", 5, 4)
expected1 := []WordCount{
{"hello", 5},
{"you", 3},
{"and", 2},
{"dont", 2},
}
expected2 := []WordCount{
{"hello", 5},
{"dont", 2},
{"everyone", 2},
{"look", 2},
{"again", 1},
}
assertEqual(t, answer1, expected1)
assertEqual(t, answer2, expected2)
}
func TestDeclarationOfIndependence(t *testing.T) {
answer := topWords("declaration_of_independence.txt", 5, 6)
expected := []WordCount{
{"people", 10},
{"states", 8},
{"government", 6},
{"powers", 5},
{"assent", 4},
}
assertEqual(t, answer, expected)
}