-
Notifications
You must be signed in to change notification settings - Fork 0
/
crib_test.go
208 lines (192 loc) · 5.66 KB
/
crib_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package mono
import (
"testing"
)
func TestNewCrib(t *testing.T) {
c := NewCrib("", "", 0)
expected := Crib{ct_: "", crib_: "", pt_: "", position_: 0, possible_: false, fixed_key_: nil}
if c != expected {
t.Errorf("c should be %v, but is actually %v\n", expected, c)
}
c = NewCrib("N EASSTH EIN GIVIC ANDI N EWORRID ENORSC", "a smooth sea", 0)
expected_ct := "NEASSTHEINGIVICANDINEWORRIDENORSC"
expected_crib := "asmoothsea"
expected_position := 0
expected_possible := true
if c.ct_ != expected_ct {
t.Errorf("c.ct_ should be %s, but is actually %s\n", expected_ct, c.ct_)
}
if c.Get_ct() != expected_ct {
t.Errorf("c.Get_ct() should be %s, but is actually %s\n", expected_ct, c.Get_ct())
}
if c.crib_ != expected_crib {
t.Errorf("c.crib_ should be %s, but is actually %s\n", expected_crib, c.crib_)
}
if c.Get_crib_string() != expected_crib {
t.Errorf("c.Get_crib_string() should be %s, but is actually %s\n", expected_crib, c.Get_crib_string())
}
if c.position_ != expected_position {
t.Errorf("c.position_ should be %d, but is actually %d\n", expected_position, c.position_)
}
if c.Get_position() != expected_position {
t.Errorf("c.Get_position() should be %d, but is actually %d\n", expected_position, c.Get_position())
}
if c.possible_ != expected_possible {
t.Errorf("c.possible_ should be %d, but is actually %d\n", expected_possible, c.possible_)
}
if c.Is_possible() != expected_possible {
t.Errorf("c.Is_possible() should be %d, but is actually %d\n", expected_possible, c.Is_possible())
}
if c.fixed_key_ == nil {
t.Error("c.fixed_key should be non-nil")
}
if c.Get_fixed_key() == nil {
t.Error("c.Get_fixed_key() should be non-nil")
}
}
func TestMove(t *testing.T) {
cc := Crib{}
c := &cc
c.Move_right()
if c.position_ != 0 {
t.Error("c.position_ should be 0 after Move_right()")
}
c.Next_right()
if c.position_ != 0 {
t.Error("c.position_ should be 0 after Next_right()")
}
c.place_at(10)
if c.position_ != 0 {
t.Error("c.position_ should be 0 after place_at(10)")
}
cc = NewCrib("AAABBBCCDD", "aaabbbccdd", 0)
c = &cc
c.Move_right()
if c.position_ != 0 {
t.Error("c.position_ should be 0 after Move_right()")
}
cc = NewCrib("AAABBBCCDD", "ccdd", 0)
c = &cc
c.Next_right()
c.Next_right()
c.Next_right()
if c.position_ != 6 {
t.Error("c.position_ should be 6 after Next_right()")
}
c.Next_left()
if c.position_ != 4 {
t.Error("c.position_ should be 4 after Next_left()")
}
c.Next_left()
if c.position_ != 1 {
t.Error("c.position_ should be 4 after Next_left()")
}
c.Next_left()
if c.position_ != 1 {
t.Error("c.position_ should be 4 after Next_left()")
}
c.place_at(20)
if c.position_ != 1 {
t.Error("c.position_ should be 4 after place_at()")
}
c.place_at(-1)
if c.position_ != 1 {
t.Error("c.position_ should be 1 after place_at(-1)")
}
cc = NewCrib("N EASSTH EIN GIVIC ANDI N EWORRID ENORSC", "a smooth sea", 0)
c = &cc
c.Move_left()
if c.position_ != 0 {
t.Error("c.position_ should be 0 after Move_left()")
}
if !c.Is_possible() {
t.Error("Should be possible after Move_left()")
}
c.Move_right()
if c.position_ != 1 {
t.Error("c.position_ should be 1 after Move_right()")
}
if c.Is_possible() {
t.Error("Should not be possible after Move_right()")
}
c.Next_right()
if c.position_ != 1 {
t.Error("c.position_ should be 1 after Next_right()")
}
if c.Is_possible() {
t.Error("Should not be possible after Next_right()")
}
cc = NewCrib("N EASSTH EIN GIVIC ANDI N EWORRID ENORSC", "a smooth", 0)
c = &cc
c.Next_right()
if c.position_ != 20 {
t.Error("c.position_ should be 20 after Next_right()")
}
if !c.Is_possible() {
t.Error("Should be possible after Next_right()")
}
c.Next_right()
if c.position_ != 20 {
t.Error("c.position_ should be 20 after Next_right()")
}
if !c.Is_possible() {
t.Error("Should be possible after Next_right()")
}
c.Next_left()
if c.position_ != 0 {
t.Error("c.position_ should be 0 after Next_left()")
}
if !c.Is_possible() {
t.Error("Should be possible after Next_left()")
}
}
func TestGet_pt(t *testing.T) {
cc := NewCrib("N EASSTH EIN GIVIC ANDI N EWORRID ENORSC", "a smooth", 0)
c := &cc
expected_pt := "asmooths.a.....ma..as......sa..o."
if c.Get_pt() != expected_pt {
t.Errorf("c.Get_pt() should be %s, but actually is %s\n", expected_pt, c.Get_pt())
}
c.Next_right()
expected_pt = ".a.....at..t.t...ht.asmootha.mo.."
if c.Get_pt() != expected_pt {
t.Errorf("c.Get_pt() should be %s, but actually is %s\n", expected_pt, c.Get_pt())
}
}
func TestClear(t *testing.T) {
cc := NewCrib("N EASSTH EIN GIVIC ANDI N EWORRID ENORSC", "a smooth", 0)
c := &cc
c.Next_right()
c.Clear()
if c.crib_ != "" {
t.Errorf("c.crib_ should be blank but is %s\n", c.crib_)
}
if c.position_ != 0 {
t.Errorf("c.position_ should be zero but is %d\n", c.position_)
}
}
func TestPossible_positions(t *testing.T) {
possible_positions := Possible_positions("N EASSTH EIN GIVIC ANDI N EWORRID ENORSC", "a smooth")
if _, ok := possible_positions[0]; !ok {
t.Error("0 should be a possible position")
}
if _, ok := possible_positions[20]; !ok {
t.Error("20 should be a possible position")
}
if _, ok := possible_positions[15]; ok {
t.Error("15 should not be a possible position")
}
possible_positions = Possible_positions("AAABBBCCDD", "aabb")
if len(possible_positions) != 3 {
t.Errorf("len(possible_positions) should be 3, but actually is %d", len(possible_positions))
}
if _, ok := possible_positions[1]; !ok {
t.Errorf("possible_positions[1] should exist")
}
if _, ok := possible_positions[4]; !ok {
t.Errorf("possible_positions[4] should exist")
}
if _, ok := possible_positions[6]; !ok {
t.Errorf("possible_positions[6] should exist")
}
}