-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
59 lines (42 loc) · 1.33 KB
/
test.py
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
import unittest
from game import Game
from evaluate import evaluate
class Test(unittest.TestCase):
def test_castling(self):
self.assertEqual('foo'.upper(), 'FOO')
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_white_knight_positions(self):
game = Game()
moves = [ "b1a3", "g1h3" ]
attrs = [ "white_knight_on_edge1", "white_knight_on_edge2" ]
for i in range(2):
move = game.board.parse_uci(moves[i])
attr = attrs[i]
game.move(move)
score = evaluate(game)
self.assertTrue(getattr(game, attr))
self.assertEqual(score, -50)
game.undo()
score = evaluate(game)
self.assertFalse(getattr(game, attr))
self.assertEqual(score, 0)
def test_black_knight_positions(self):
game = Game()
move = game.board.parse_uci("d2d3")
game.move(move)
moves = [ "b8a6", "g8h6" ]
attrs = [ "black_knight_on_edge1", "black_knight_on_edge2" ]
for i in range(2):
move = game.board.parse_uci(moves[i])
attr = attrs[i]
game.move(move)
score = evaluate(game)
self.assertTrue(getattr(game, attr))
self.assertEqual(score, 50)
game.undo()
score = evaluate(game)
self.assertFalse(getattr(game, attr))
self.assertEqual(score, 0)
if __name__ == '__main__':
unittest.main()