annotate tests/test_error.py @ 70:351fc97bb996

add error computation + test functions
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:22:44 -0800
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 test error computation functionality
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import numpy as np
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import os
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import unittest
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 from tvii import error
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 class ErrorTest(unittest.TestCase):
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 def test_error_computation(self):
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 """test error computation"""
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 def square(x):
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 return x*x
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 x = [[1], [2], [3]]
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 y = np.array([0, 3, 8])
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 yhat, _err = error.error(square, x, y)
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 assert list(yhat) == [1, 4, 9]
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 assert list(_err) == [1, 1, 1]
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 if __name__ == '__main__':
351fc97bb996 add error computation + test functions
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 unittest.main()