-
Notifications
You must be signed in to change notification settings - Fork 0
/
balance_test.go
85 lines (64 loc) · 2.05 KB
/
balance_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
package balance
import "testing"
func TestValidCheck(t *testing.T) {
cases := []string{"", "[]", "[()]", "[[]]", "([()])", "{[()]}", "[[[[[[[[[[[[[[[{{{{{{{{{{}}}}}}}}}}]]]]]]]]]]]]]]]", "[[[]]][[{}]()()]{{()[][()]}}"}
for _, str := range cases {
valid, err := Check(str)
if !valid {
t.Errorf("Text: %q, Status: Invalid, Expected: Valid, Error: %v", str, err)
}
}
}
func TestMismatchError(t *testing.T) {
cases := []string{"([)]", "([)", ")()(", "([]{)}", "[[[]]][[{}]()(]{{()[][()]}}"}
for _, str := range cases {
valid, err := Check(str)
if valid {
t.Errorf("Text: %q, Status: Valid, Expected: Invalid, Error: %v", str, err)
}
if _, ok := err.(*MismatchError); !ok {
t.Errorf("Text: %q, Error: %v, Expected: MismatchError", str, err)
}
}
}
func TestUnclosedParenthesesError(t *testing.T) {
cases := []string{"(((", "[[]", "(())(", "{{{()}}", "[[[]]][[{}]()()]{{()[][()]}}{{"}
for _, str := range cases {
valid, err := Check(str)
if valid {
t.Errorf("Text: %q, Status: Valid, Expected: Invalid, Error: %v", str, err)
}
if _, ok := err.(*UnclosedParenthesesError); !ok {
t.Errorf("Text: %q, Error: %v, Expected: UnclosedParenthesesError", str, err)
}
}
}
func TestUnknownCharacterError(t *testing.T) {
cases := []string{"((a))", "[]abc", "abf", "[[[]]][[{}]()()]{{()[][()]a}}"}
for _, str := range cases {
valid, err := Check(str)
if valid {
t.Errorf("Text: %q, Status: Valid, Expected: Invalid, Error: %v", str, err)
}
if _, ok := err.(*UnknownCharacterError); !ok {
t.Errorf("Text: %q, Error: %v, Expected: UnknownCharacterError", str, err)
}
}
}
func TestCheckCustom(t *testing.T) {
cases := []struct {
str, opens, closes string
valid bool
}{
{"<>", "<", ">", true},
{"{{}}\\/", "\\{", "/}", true},
{")))()(((", ")", "(", true},
{"<<>><<<>>", "<", ">)", false},
}
for _, c := range cases {
valid, err := CheckCustom(c.str, c.opens, c.closes)
if valid != c.valid {
t.Errorf("Text: %q, Valid: %v, Expected: %v, Error: %v", c.str, valid, c.valid, err)
}
}
}