-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_test.py
48 lines (37 loc) · 1.32 KB
/
check_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
import unittest
from IPython.display import Markdown, display
import numpy as np
def printmd(string):
display(Markdown(string))
V_opt = np.zeros((4,12))
V_opt[0:13][0] = -np.arange(3, 15)[::-1]
V_opt[0:13][1] = -np.arange(3, 15)[::-1] + 1
V_opt[0:13][2] = -np.arange(3, 15)[::-1] + 2
V_opt[3][0] = -13
pol_opt = np.hstack((np.ones(11), 2, 0))
V_true = np.zeros((4,12))
for i in range(3):
V_true[0:13][i] = -np.arange(3, 15)[::-1] - i
V_true[1][11] = -2
V_true[2][11] = -1
V_true[3][0] = -17
def get_long_path(V):
return np.array(np.hstack((V[0:13][0], V[1][0], V[1][11], V[2][0], V[2][11], V[3][0], V[3][11])))
def get_optimal_path(policy):
return np.array(np.hstack((policy[2][:], policy[3][0])))
class Tests(unittest.TestCase):
def td_prediction_check(self, V):
to_check = get_long_path(V)
soln = get_long_path(V_true)
np.testing.assert_array_almost_equal(soln, to_check)
def td_control_check(self, policy):
to_check = get_optimal_path(policy)
np.testing.assert_equal(pol_opt, to_check)
check = Tests()
def run_check(check_name, func):
try:
getattr(check, check_name)(func)
except check.failureException as e:
printmd('**<span style="color: red;">PLEASE TRY AGAIN</span>**')
return
printmd('**<span style="color: green;">PASSED</span>**')