Repository navigation
Expand file tree
/
Copy pathTests.py
More file actions
67 lines (52 loc) · 1.57 KB
/
Copy pathTests.py
File metadata and controls
67 lines (52 loc) · 1.57 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
from State import State
from Oracle import oracle_value
import numpy as np
import ValidationData
def test_move_make():
board = State()
board.push(4)
expected = np.zeros((2, 3, 3), dtype=int)
expected[0, 1, 1] = 1
assert np.array_equal(board.vectorise_chlast(), expected), f"Error: {board.vectorise_chlast()} != {expected}"
def test_make_unmake():
board = State()
moves = [0, 1, 2, 3, 4]
for move in moves:
board.push(move)
board.pop()
for move in moves:
board.push(move)
for move in moves:
board.pop()
expected = np.zeros((2, 3, 3), dtype=int)
assert np.array_equal(board.vectorise_chlast(), expected), f"Error: {board.vectorise_chlast()} != {expected}"
def test_oracle():
board = State()
if not oracle_value(board) == 0:
print("Error: value(b) != 0")
print(f"{oracle_value(board) = }")
print(board)
exit(1)
board.play(0)
board.play(1)
if not oracle_value(board) == 1:
print("Error: value(b) != 1")
print(f"{oracle_value(board) = }")
print(board)
exit(1)
board.play(2)
board.play(4)
board.play(3)
if not oracle_value(board) == -1:
print("Error: value(b) != -1")
print(f"{oracle_value(board) = }")
print(board)
exit(1)
def more_oracle_tests():
states = map(State, ValidationData.x_val)
values = ValidationData.y_val
assert all(v == oracle_value(s) for v, s in zip(values, states))
if __name__ == "__main__":
test_move_make()
test_make_unmake()
test_oracle()