forked from notnil/chess
-
Notifications
You must be signed in to change notification settings - Fork 2
/
board_test.go
38 lines (35 loc) · 921 Bytes
/
board_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
package chess
import (
"testing"
)
func TestBoardTextSerialization(t *testing.T) {
fen := "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
b := &Board{}
if err := b.UnmarshalText([]byte(fen)); err != nil {
t.Fatal("recieved unexpected error", err)
}
txt, err := b.MarshalText()
if err != nil {
t.Fatal("recieved unexpected error", err)
}
if fen != string(txt) {
t.Fatalf("fen expected board string %s but got %s", fen, string(txt))
}
}
func TestBoardBinarySerialization(t *testing.T) {
g := NewGame()
board := g.Position().Board()
b, err := board.MarshalBinary()
if err != nil {
t.Fatal("recieved unexpected error", err)
}
cpBoard := &Board{}
err = cpBoard.UnmarshalBinary(b)
if err != nil {
t.Fatal("recieved unexpected error", err)
}
s := "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"
if s != cpBoard.String() {
t.Fatalf("expected board string %s but got %s", s, cpBoard.String())
}
}