-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathchallenge10_test.go
102 lines (90 loc) · 1.64 KB
/
challenge10_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
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
package challenge10
import (
"testing"
)
func TestNoClosers(t *testing.T) {
if !HasValidClosers("The quack brown fax jumped over the dazy dog.") {
t.Fail()
}
}
func TestSingleCloser(t *testing.T) {
if !HasValidClosers("(Y)") {
t.Fail()
}
}
func TestNoOpener(t *testing.T) {
if HasValidClosers("hi)") {
t.Fail()
}
}
func TestNoCloser(t *testing.T) {
if HasValidClosers("(hi") {
t.Fail()
}
}
func TestParens(t *testing.T) {
if !HasValidClosers("()") {
t.Error("Bad valid order")
}
if HasValidClosers(")(") {
t.Error("Bad invalid order")
}
}
func TestBrackets(t *testing.T) {
if !HasValidClosers("[]") {
t.Error("Bad valid order")
}
if HasValidClosers("][") {
t.Error("Bad invalid order")
}
}
func TestBraces(t *testing.T) {
if !HasValidClosers("{}") {
t.Error("Bad valid order")
}
if HasValidClosers("}{") {
t.Error("Bad invalid order")
}
}
func TestLtGt(t *testing.T) {
if !HasValidClosers("<>") {
t.Error("Bad valid order")
}
if HasValidClosers("><") {
t.Error("Bad invalid order")
}
}
func TestValidNesting(t *testing.T) {
if !HasValidClosers("{[(<>)[<<{}>>]]}") {
t.Fail()
}
}
func TestInvalidNesting(t *testing.T) {
if HasValidClosers("({[<)}]>") {
t.Fail()
}
}
func TestDeepNesting(t *testing.T) {
l := 20000
rs := make([]rune, 0, l*2)
for i := 1; i <= l; i++ {
fizz := i%3 == 0
buzz := i%5 == 0
if fizz && buzz {
rs = append(rs, '(')
} else if fizz {
rs = append(rs, '[')
} else if buzz {
rs = append(rs, '{')
} else {
rs = append(rs, '<')
}
}
for i := l - 1; i >= 0; i-- {
rs = append(rs, openers[rs[i]])
}
s := string(rs)
if !HasValidClosers(s) {
t.Fail()
}
}