-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpiece_test.go
More file actions
47 lines (42 loc) · 828 Bytes
/
piece_test.go
File metadata and controls
47 lines (42 loc) · 828 Bytes
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
package chess
import (
"bytes"
"testing"
)
func TestPieceString(t *testing.T) {
tables := []struct {
piece PieceType
str string
}{
{King, "k"},
{Queen, "q"},
{Rook, "r"},
{Bishop, "b"},
{Knight, "n"},
{Pawn, "p"},
}
for _, table := range tables {
if table.piece.String() != table.str {
t.Errorf("String version of piece was incorrect.")
}
}
}
func TestBytesForPieceTypes(t *testing.T) {
tests := []struct {
pieceType PieceType
expected []byte
}{
{King, []byte{'k'}},
{Queen, []byte{'q'}},
{Rook, []byte{'r'}},
{Bishop, []byte{'b'}},
{Knight, []byte{'n'}},
{Pawn, []byte{'p'}},
{NoPieceType, []byte{}},
}
for _, tt := range tests {
if !bytes.Equal(tt.pieceType.Bytes(), tt.expected) {
t.Fatalf("expected %v but got %v", tt.expected, tt.pieceType.Bytes())
}
}
}