-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgn_test.go
139 lines (121 loc) · 3.04 KB
/
pgn_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
package pgn
import (
"testing"
)
func TestGame_GetTag(t *testing.T) {
game := &Game{
tags: map[string]string{
"CustomTag": "CustomValue",
},
}
if got := game.GetTag("CustomTag"); got != "CustomValue" {
t.Errorf("Game.GetTag() = %v, want %v", got, "CustomValue")
}
// Test non-existent tag
if got := game.GetTag("NonExistent"); got != "" {
t.Errorf("Game.GetTag() for non-existent tag = %v, want empty string", got)
}
}
func TestGame_TagPairs(t *testing.T) {
tags := map[string]string{
"Tag1": "Value1",
"Tag2": "Value2",
}
game := &Game{
tags: tags,
}
got := game.TagPairs()
if len(got) != len(tags) {
t.Errorf("Game.TagPairs() length = %v, want %v", len(got), len(tags))
}
for k, v := range tags {
if gotValue := got[k]; gotValue != v {
t.Errorf("Game.TagPairs()[%v] = %v, want %v", k, gotValue, v)
}
}
}
func TestGame_StandardTags(t *testing.T) {
game := &Game{
tags: map[string]string{
"Event": "Test Event",
"Site": "Test Site",
"Round": "1",
"Date": "2024.01.01",
"White": "Player 1",
"Black": "Player 2",
},
}
tests := []struct {
name string
got string
expected string
fn func() string
}{
{"Event", game.Event(), "Test Event", game.Event},
{"Site", game.Site(), "Test Site", game.Site},
{"Round", game.Round(), "1", game.Round},
{"Date", game.Date(), "2024.01.01", game.Date},
{"White", game.White(), "Player 1", game.White},
{"Black", game.Black(), "Player 2", game.Black},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.fn(); got != tt.expected {
t.Errorf("Game.%s() = %v, want %v", tt.name, got, tt.expected)
}
})
}
// Test missing tags return empty string
emptyGame := &Game{
tags: map[string]string{},
}
if got := emptyGame.Event(); got != "" {
t.Errorf("Game.Event() with no tags = %v, want empty string", got)
}
}
func TestGame_Result(t *testing.T) {
game := &Game{
result: "1-0",
}
if got := game.Result(); got != "1-0" {
t.Errorf("Game.Result() = %v, want %v", got, "1-0")
}
// Test empty result
emptyGame := &Game{}
if got := emptyGame.Result(); got != "" {
t.Errorf("Game.Result() empty game = %v, want empty string", got)
}
}
func TestGame_Moves(t *testing.T) {
moves := map[int]*Move{
1: {MoveNumber: 1, MoveWhite: "e4", MoveBlack: "e5"},
2: {MoveNumber: 2, MoveWhite: "Nf3", MoveBlack: "Nc6"},
}
game := &Game{
moves: moves,
}
got := game.Moves()
if len(got) != len(moves) {
t.Errorf("Game.Moves() length = %v, want %v", len(got), len(moves))
}
for k, v := range moves {
if gotMove := got[k]; gotMove != v {
t.Errorf("Game.Moves()[%v] = %v, want %v", k, gotMove, v)
}
}
}
func TestGame_GetMove(t *testing.T) {
move := &Move{MoveNumber: 1, MoveWhite: "e4", MoveBlack: "e5"}
game := &Game{
moves: map[int]*Move{
1: move,
},
}
if got := game.GetMove(1); got != move {
t.Errorf("Game.GetMove() = %v, want %v", got, move)
}
// Test non-existent move
if got := game.GetMove(999); got != nil {
t.Errorf("Game.GetMove() for non-existent move = %v, want nil", got)
}
}