-
Notifications
You must be signed in to change notification settings - Fork 0
/
punchit_test.go
68 lines (58 loc) · 1.35 KB
/
punchit_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
60
61
62
63
64
65
66
67
68
package punchit
import (
"strings"
"testing"
)
func TestPunchCharValid(t *testing.T) {
test := "A"
exp := "100100000000"
col, err := PunchChar(test)
if err != nil {
t.Errorf("Unexpected error:\n%v", err)
}
if len(col) != 12 {
t.Errorf("Expected length 12, but got %v", len(col))
}
if col != exp {
t.Errorf("Expected '%s', but got %v", exp, col)
}
}
func TestPunchCharInvalid(t *testing.T) {
test := "["
_, err := PunchChar(test)
if err == nil {
t.Errorf("Expected error for invalid character '%s', but got nil", test)
}
}
func TestPunchLine(t *testing.T) {
test := "hello world"
card, err := PunchLine(test)
if err != nil {
t.Errorf("Unexpected error:\n%v", err)
}
if strings.TrimSpace(card.src) != test {
t.Errorf("Expected '%s', but got %v", test, card.src)
}
t.Logf(card.String())
for i, col := range card.punches {
if len(col) != 12 {
t.Errorf("Col %d: Expected length 12, but got %d", i, len(col))
}
}
for i := 0; i < 12; i++ {
row := card.GetRow(i)
if len(row) != 80 {
t.Errorf("Row %d: Expected length 80, but got %d", i, len(row))
}
}
}
func TestPunchLines(t *testing.T) {
test := []string{"first card", "second card", "third card"}
deck, err := PunchLines(test)
if err != nil {
t.Errorf("Unexpected error:\n%v", err)
}
if len(deck) != 3 {
t.Errorf("Expected deck of length 3, but got %v", len(deck))
}
}