-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
103 lines (84 loc) · 3.25 KB
/
test.py
File metadata and controls
103 lines (84 loc) · 3.25 KB
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
"""
Author: Hannah Webb
Creation Date: 12/10/25
Purpose: Test cases for checkers.
"""
from checkers import Board
from checkers import Game
def test_is_valid_position(): # tests for is_valid_position()
fn_name = 'is_valid_position'
game = Game()
game.board = Board(8)
game.board.size = 8
expected = True
result = game.is_valid_position("a1", 8)
error_message = f'while testing {fn_name}, expected {expected} got {result}'
assert expected == result, error_message
expected = False
result = game.is_valid_position("i1", 8)
error_message = f'while testing {fn_name}, expected {expected} got {result}'
assert expected == result, error_message
print(f'{fn_name} tests passed')
def test_get_piece_at_name(): # tests for get_piece_at_name()
fn_name = 'get_piece_at_name'
board = Board(8)
board_str = board.create()
game = Game()
game.board = board
expected = 'b'
result = game.get_piece_at_name("a1", board_str)
error_message = f'while testing {fn_name}, expected {expected} got {result}'
assert expected == result, error_message
expected = '-'
result = game.get_piece_at_name("b1", board_str)
error_message = f'while testing {fn_name}, expected {expected} got {result}'
assert expected == result, error_message
print(f'{fn_name} tests passed')
def test_get_moves(): # tests for get_moves()
fn_name = 'get_moves'
board = Board(4)
board_str = board.create()
game = Game()
game.board = board
expected = "d2 b2 "
result = game.get_moves("c1", board_str)
error_message = f'while testing {fn_name}, expected "{expected}" got "{result}"'
assert expected == result, error_message
expected = "c3 "
result = game.get_moves("d4", board_str)
error_message = f'while testing {fn_name}, expected "{expected}" got "{result}"'
assert expected == result, error_message
print(f'{fn_name} tests passed')
def test_king(): # tests for king()
fn_name = 'king'
board = Board(4)
board_str = board.create()
game = Game()
game.board = board
# creates a board where we've inserted a b into the last row
pos = game.get_pos_at_name('b4', board_str)
board_str = board_str[:pos] + 'b' + board_str[pos + 1:]
# checks to ensure that this b is kinged when we run king()
expected = board_str[:pos] + 'B' + board_str[pos + 1:]
result = game.king(board_str)
error_message = f'while testing {fn_name}, expected "{expected}" got "{result}"'
assert expected == result, error_message
# creates a fresh board
board_str = board.create()
# creates a board where we've inserted a r into the first row
pos = game.get_pos_at_name('c1', board_str)
board_str = board_str[:pos] + 'r' + board_str[pos + 1:]
# checks to ensure that this r is kinged when we run king()
expected = board_str[:pos] + 'R' + board_str[pos + 1:]
result = game.king(board_str)
error_message = f'while testing {fn_name}, expected "{expected}" got "{result}"'
assert expected == result, error_message
print(f'{fn_name} tests passed')
def test_all(): # runs all tests
test_is_valid_position()
test_get_piece_at_name()
test_get_moves()
test_king()
print("All tests passed!")
if __name__ == "__main__":
test_all()