-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
33 lines (30 loc) · 867 Bytes
/
main_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
package main
import "testing"
func TestTotalScore(t *testing.T) {
for n, tc := range []struct {
input []byte
score int
garbage int
}{
{[]byte(`{}`), 1, 0},
{[]byte(`{{{}}}`), 6, 0},
{[]byte(`{{},{}}`), 5, 0},
{[]byte(`{{{},{},{{}}}}`), 16, 0},
{[]byte(`{<a>,<a>,<a>,<a>}`), 1, 4},
{[]byte(`{{<ab>},{<ab>},{<ab>},{<ab>}}`), 9, 8},
{[]byte(`{{<!!>},{<!!>},{<!!>},{<!!>}}`), 9, 0},
{[]byte(`{{<a!>},{<a!>},{<a!>},{<ab>}}`), 3, 17},
{[]byte(`<>`), 0, 0},
{[]byte(`<random characters>`), 0, 17},
{[]byte(`<<<<>`), 0, 3},
{[]byte(`<{!>}>`), 0, 2},
{[]byte(`<!!>`), 0, 0},
{[]byte(`<!!!>>`), 0, 0},
{[]byte(`<{o"i!a,<{i<a>`), 0, 10},
} {
score, garbage := scoreAndGarbage(tc.input)
if score != tc.score || garbage != tc.garbage {
t.Errorf("[%d] got %d, %d; want %d, %d", n, score, garbage, tc.score, tc.garbage)
}
}
}