-
Notifications
You must be signed in to change notification settings - Fork 135
/
bitboard_test.go
55 lines (48 loc) · 983 Bytes
/
bitboard_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
package chess
import "testing"
type bitboardTestPair struct {
initial uint64
reversed uint64
}
var (
tests = []bitboardTestPair{
{
uint64(1),
uint64(9223372036854775808),
},
{
uint64(18446744073709551615),
uint64(18446744073709551615),
},
{
uint64(0),
uint64(0),
},
}
)
func TestBitboardReverse(t *testing.T) {
for _, p := range tests {
r := uint64(bitboard(p.initial).Reverse())
if r != p.reversed {
t.Fatalf("bitboard reverse of %s expected %s but got %s", intStr(p.initial), intStr(p.reversed), intStr(r))
}
}
}
func TestBitboardOccupied(t *testing.T) {
m := map[Square]bool{
B3: true,
}
bb := newBitboard(m)
if bb.Occupied(B3) != true {
t.Fatalf("bitboard occupied of %s expected %t but got %t", bb, true, false)
}
}
func BenchmarkBitboardReverse(b *testing.B) {
for i := 0; i < b.N; i++ {
u := uint64(9223372036854775807)
bitboard(u).Reverse()
}
}
func intStr(i uint64) string {
return bitboard(i).String()
}