/
chess_validator_test.py
84 lines (66 loc) · 2.92 KB
/
chess_validator_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
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
""" chess_validator_test: tests for chess_validator """
import unittest
import utils
import chess_validator as validator
class TestValidator(unittest.TestCase):
def test_are_coordinates_valid(self):
expected = True
for coords in [('a', '1'), ('d', '5'), ('h', '8')]:
actual = validator.are_coordinates_valid(coords[0], coords[1])
self.assertEqual(expected, actual)
expected = False
for coords in [('a', '-1'), ('z', '5'), ('z', '17'), ('A', '5')]:
actual = validator.are_coordinates_valid(coords[0], coords[1])
self.assertEqual(expected, actual)
def test_validate_move_case(self):
expected = True
for piece in ['K','Q','N','B','R']:
actual = validator.validate_move_case(piece +'f3')
self.assertEqual(expected, actual)
expected = True
for col in utils.COLUMN_NAMES:
actual = validator.validate_move_case(col +'3')
self.assertEqual(expected, actual)
expected = False
for piece in ['K','Q','N','B','R']:
actual = validator.validate_move_case(piece +'3')
self.assertEqual(expected, actual)
for col in utils.COLUMN_NAMES:
actual = validator.validate_move_case(col)
self.assertEqual(expected, actual)
def test_validate_eat_case(self):
expected = True
for input_move in ['Kxf3', 'axb2', 'Rxd2']:
actual = validator.validate_eat_case(input_move)
self.assertEqual(expected, actual)
expected = False
for input_move in ['Kf3', 'a2', 'Rxd']:
actual = validator.validate_eat_case(input_move)
self.assertEqual(expected, actual)
def test_is_valid_promotion(self):
expected = True
actual = validator.is_valid_promotion('a8', 'Q')
self.assertEqual(expected,actual, msg = 'should be valid here')
expected = True
actual = validator.is_valid_promotion('b1', 'N')
self.assertEqual(expected,actual, msg = 'should be valid here too')
expected = False
for new_piece in ['a','b','c','d','e','f','g','h','K']:
actual = validator.is_valid_promotion('a8',new_piece)
self.assertEqual(expected,actual, msg = 'no way this is valid')
def test_is_user_move_valid(self):
expected = True
k = 1
for input_move in ['a2','axb2','Bf3','Bxa2']:
actual = validator.is_user_move_valid(input_move)
self.assertEqual(expected, actual, msg='Error on test # %i: %s' % (k, input_move))
k += 1
expected = False
k = 1
for input_move in ['ax2','B3','Abcd']:
#print input_move, actual
actual = validator.is_user_move_valid(input_move)
self.assertEqual(expected, actual, msg='Error on test # %i: %s' %(k,input_move) )
k += 1
if __name__ == '__main__':
unittest.main()