annotate tests/test_transpose.py @ 80:3c7927f59b05

notes to self re deep neural networks
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:43:42 -0800
parents 9d55e0299c3f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 test matrix data transposition
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import unittest
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 from tvii.transpose import transpose
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 from tvii.transpose import NotAMatrix
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 class TestTranspose(unittest.TestCase):
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 def test_transpose(self):
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 data = [[1.0, 0.0],
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 [2.0, -1.0],
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 [3.0, -2.0],
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 [4.0, -3.0]]
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 transposed = [[1.0, 2., 3., 4.],
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 [0., -1., -2., -3]]
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 assert (transpose(data) == transposed)
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 def test_not_a_matrix(self):
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 not_a_matrix = [[1,2,3],
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 [4,5,6],
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 [7, 8, 9, 10] # oops
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 ]
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 e = None
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 try:
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 transpose(not_a_matrix)
71
9d55e0299c3f fix scoping for python 3.6
Jeff Hammel <k0scist@gmail.com>
parents: 69
diff changeset
32 except NotAMatrix as _e:
9d55e0299c3f fix scoping for python 3.6
Jeff Hammel <k0scist@gmail.com>
parents: 69
diff changeset
33 e = _e
69
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34 assert e is not None
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35 assert isinstance(e, NotAMatrix)
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37 if __name__ == '__main__':
0bb36ae047c3 test matrix transposition
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 unittest.main()