-
Notifications
You must be signed in to change notification settings - Fork 6
/
chaostest.py
55 lines (44 loc) · 1.49 KB
/
chaostest.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
54
55
###############################################################################
#
# CSCI 4446 - Chaotic Dynamics
#
# File: chaostest.py
# Author: Ken Sheedlo
#
# Testing facilities for chaos programs.
#
###############################################################################
import unittest
from numpy.linalg import norm
class TestCase(unittest.TestCase):
'''
Extends the standard unittest TestCase with relevant asserts.
'''
def assertDataFits(self, ts, xs, func, **kwargs):
'''
Assert that (t, x) data points fit the given function.
'''
delta = kwargs.get('delta')
places = kwargs.get('places')
f_args = kwargs.get('f_args', tuple())
assert_kwargs = dict()
if delta is not None:
assert_kwargs['delta'] = delta
elif places is not None:
assert_kwargs['places'] = places
for (t_i, x_i) in zip(ts, xs):
x_diff = norm(x_i - func(t_i, *f_args))
self.assertAlmostEqual(delta, 0.0, **assert_kwargs)
def assertArrayEqual(self, rhs, lhs, **kwargs):
'''
Assert array equality.
'''
delta = kwargs.get('delta')
places = kwargs.get('places')
assert_kwargs = dict()
if delta is not None:
assert_kwargs['delta'] = delta
elif places is not None:
assert_kwargs['places'] = places
for (foo, baz) in zip(rhs, lhs):
self.assertAlmostEqual(foo, baz, **assert_kwargs)