-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
53 lines (39 loc) · 1.49 KB
/
tests.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
from states import GameState, TOAD, FROG, BLANK
def test_state():
board = [1, 0, 0, -1]
G = GameState(board)
assert str(G) == '|T| | |F|'
assert G.num_frogs == G.num_toads == 1
assert G.toad_locs == [None, 0]
assert G.frog_locs == [None, 3], G.frog_locs
def test_get_legal_moves():
# G1 = GameState([1, 0, 0, -1], TOAD)
# assert G1.get_legal_moves() == [1], G1.get_legal_moves()
# G2 = GameState([1, -1, 0, 1, 0, 0, -1, -1, -1, 0, 1, -1], TOAD)
# assert G2.get_legal_moves() == [2, 3], f'{G2.get_legal_moves()}'
# G3 = GameState([1, -1, 0, 1, 0, 0, -1, -1, -1, 0, 1, -1], FROG)
# assert G3.get_legal_moves() == [2, 5]
G1 = GameState([1, 0, 0, -1], TOAD)
assert G1.get_legal_moves() == set([1]), G1.get_legal_moves()
G2 = GameState([1, -1, 0, 1, 0, 0, -1, -1, -1, 0, 1, -1], TOAD)
assert G2.get_legal_moves() == set([2, 3]), f'{G2.get_legal_moves()}'
G3 = GameState([1, -1, 0, 1, 0, 0, -1, -1, -1, 0, 1, -1], FROG)
assert G3.get_legal_moves() == set([2, 5])
def test_make_move():
G = GameState([1, 0, 0, -1])
G2 = GameState([0, 1, 0, -1])
G.make_move(1)
assert G == G2, f"{G} not equal to {G2}"
def test_is_P():
G = GameState([1, 1, -1, 0, 1, -1, -1, 0, 1, -1])
assert G.is_P()
G2 = GameState([1, 1, 1, 0, 0, -1, -1, -1])
assert not G2.is_P()
def main():
test_state()
test_get_legal_moves()
test_make_move()
test_is_P()
print("All tests passed!")
if __name__ == "__main__":
main()