Skip to content

Commit 3d292d3

Browse files
committed
homework: more tests
1 parent ff3e15b commit 3d292d3

File tree

6 files changed

+64
-10
lines changed

6 files changed

+64
-10
lines changed

bitboard_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package main
23

34
import (

castlings_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package main
32

43
import (
@@ -85,7 +84,7 @@ func Test_parseCastlings(t *testing.T) {
8584
{"", "kq", castlings(shortB | longB)},
8685
{"", "Kk", castlings(shortW | shortB)},
8786
{"", "KQkqrr", castlings(shortW | longW | shortB | longB)},
88-
{"", "kQq", castlings( longW | shortB | longB)},
87+
{"", "kQq", castlings(longW | shortB | longB)},
8988
}
9089
for _, tt := range tests {
9190
t.Run(tt.name, func(t *testing.T) {
@@ -95,3 +94,25 @@ func Test_parseCastlings(t *testing.T) {
9594
})
9695
}
9796
}
97+
98+
func Test_castlings_String(t *testing.T) {
99+
tests := []struct {
100+
name string
101+
c castlings
102+
want string
103+
}{
104+
{"", 0, "-"},
105+
{"", castlings(shortW | longB), "Kq"},
106+
{"", castlings(shortW | longB), "Kq"},
107+
{"", castlings(shortW | longW), "KQ"},
108+
{"", castlings(shortB | longB), "kq"},
109+
{"", castlings(shortW | longB | shortB | longW), "KQkq"},
110+
}
111+
for _, tt := range tests {
112+
t.Run(tt.name, func(t *testing.T) {
113+
if got := tt.c.String(); got != tt.want {
114+
t.Errorf("castlings.String() = %v, want %v", got, tt.want)
115+
}
116+
})
117+
}
118+
}

main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ func main() {
77

88
tell("info string quits GOBIT")
99
}
10-
11-
// TODO: A credential helper: https://help.github.com/articles/caching-your-github-password-in-git/

move.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ const (
1212
SE = -NW
1313
)
1414

15-
var pieceRules[nP][]int // not pawns
15+
var pieceRules [nP][]int // not pawns
1616
type moveList struct {
1717
mv []move
1818
}
19-
func init(){
20-
pieceRules[Rook] = append(pieceRules[Rook],E)
21-
pieceRules[Rook] = append(pieceRules[Rook],W)
22-
pieceRules[Rook] = append(pieceRules[Rook],N)
23-
pieceRules[Rook] = append(pieceRules[Rook],S)
19+
func init() {
20+
pieceRules[Rook] = append(pieceRules[Rook], E)
21+
pieceRules[Rook] = append(pieceRules[Rook], W)
22+
pieceRules[Rook] = append(pieceRules[Rook], N)
23+
pieceRules[Rook] = append(pieceRules[Rook], S)
2424
}
2525

2626
func (ml *moveList) add(mv move) {

move_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import "testing"
4+
5+
func Test_moveList_add(t *testing.T) {
6+
tests := []struct {
7+
name string
8+
ml moveList
9+
mv move
10+
}{
11+
{"", moveList{},0},
12+
{"", moveList{},1},
13+
{"", moveList{},2},
14+
{"", moveList{},3},
15+
}
16+
17+
ml = moveList{}
18+
for _, tt := range tests {
19+
t.Run(tt.name, func(t *testing.T) {
20+
tt.ml = tt.ml
21+
tt.ml.add(tt.mv)
22+
ix:=len(tt.ml.mv)-1
23+
if ix<0{
24+
t.Fatalf("wrong len %v: %v %v %v",ix,tt.ml,tt.ml.mv,tt.ml.mv[0])
25+
}
26+
testMv := tt.ml.mv[ix]
27+
if testMv != tt.mv{
28+
t.Errorf("tt.ml.add() = %v. want %v",testMv,tt.mv)
29+
}
30+
})
31+
}
32+
}

uci.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ func handleGo(words []string) {
184184
tell("info string go mate not implemented")
185185
case "infinite":
186186
tell("info string go infinite not implemented")
187+
case "register":
188+
tell("info string go register not implemented")
187189
default:
188190
tell("info string go ", words[1], " not implemented")
189191
}

0 commit comments

Comments
 (0)