-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathposition_test.go
60 lines (55 loc) · 1.19 KB
/
position_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
package chess
import (
"testing"
)
func TestPositionBinary(t *testing.T) {
for _, fen := range validFENs {
pos, err := decodeFEN(fen)
if err != nil {
t.Fatal(err)
}
b, err := pos.MarshalBinary()
if err != nil {
t.Fatal(err)
}
cp := &Position{}
if err := cp.UnmarshalBinary(b); err != nil {
t.Fatal(err)
}
if pos.String() != cp.String() {
t.Fatalf("expected %s but got %s", pos.String(), cp.String())
}
}
}
func TestPositionUpdate(t *testing.T) {
for _, fen := range validFENs {
pos, err := decodeFEN(fen)
if err != nil {
t.Fatal(err)
}
{
np := pos.Update(&pos.ValidMoves()[0])
if pos.Turn().Other() != np.turn {
t.Fatal("expected other turn")
}
if pos.halfMoveClock+1 != np.halfMoveClock {
t.Fatal("expected half move clock increment")
}
if pos.board.String() == np.board.String() {
t.Fatal("expected board update")
}
}
{
np := pos.Update(nil)
if pos.Turn().Other() != np.turn {
t.Fatal("expected other turn")
}
if pos.halfMoveClock+1 != np.halfMoveClock {
t.Fatal("expected half move clock increment")
}
if pos.board.String() != np.board.String() {
t.Fatal("expected same board")
}
}
}
}