-
Notifications
You must be signed in to change notification settings - Fork 2
/
position_bitmap_test.go
61 lines (54 loc) · 1.06 KB
/
position_bitmap_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
package chess_engine
import (
"testing"
)
func Test_PositionBitmap(t *testing.T) {
unit := PositionBitmap(0)
if !unit.IsEmpty() {
t.Errorf("Expecting empty unit")
}
unit = unit.Add(E4)
unit = unit.Add(A1)
unit = unit.Add(H8)
positions := []Position{E4, A1, H8}
for _, pos := range positions {
if !unit.IsSet(pos) {
t.Errorf("Expecting %s to be set", pos)
}
}
if unit.Count() != 3 {
t.Errorf("Expecting count 3")
}
if unit.IsEmpty() {
t.Errorf("Expecting non-empty unit")
}
got := unit.ToPositions()
if len(got) != 3 {
t.Errorf("Expecting length 3")
}
for _, g := range got {
found := false
for _, p := range positions {
if g == p {
found = true
}
}
if !found {
t.Errorf("Unexpected position in %v", got)
}
}
unit = unit.ApplyMove(NewMove(E4, E5))
if unit.IsSet(E4) {
t.Errorf("Expecting e4 to be unset")
}
if !unit.IsSet(E5) {
t.Errorf("Expecting e5 to be set")
}
unit = unit.Remove(E5)
if unit.Count() != 2 {
t.Errorf("Expecting count 2")
}
if unit.IsSet(E5) {
t.Errorf("Expecting e5 to be unset")
}
}