forked from xiaohan2012/twitter-sent-dnn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.py
44 lines (39 loc) · 1.18 KB
/
test_util.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
import numpy as np
def assert_matrix_eq(actual, expected, name):
try:
assert (np.abs(actual - expected) < 1e-5).all()
print "`eq` of `%s`: OK" %(name)
except AssertionError:
print "`eq` of `%s`: Fail" %(name)
print "Actual:"
print actual
print "Expected:"
print expected
print "Equality matrix:"
print np.abs(actual - expected) < 1e-5
def assert_matrix_neq(actual, expected, name, verbose = False):
def print_verbose():
print "First:"
print actual
print "Second:"
print expected
print "Difference matrix:"
print np.abs(actual - expected)
try:
assert (np.abs(actual - expected) > 1e-5).any()
print "`neq` of %s: OK" %(name)
if verbose:
print_verbose()
except AssertionError:
print "`neq` of `%s`: Fail" %(name)
print_verbose()
def assert_about_eq(actual, expected, name):
try:
assert np.abs(actual - expected) < 1e-5
print "%s: OK" %(name)
except AssertionError:
print "%s: Fail" %(name)
print "Actual:"
print actual
print "Expected:"
print expected