comparison tests/test_transpose.py @ 69:0bb36ae047c3

test matrix transposition
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:16:16 -0800
parents
children 9d55e0299c3f
comparison
equal deleted inserted replaced
68:5916b04d0582 69:0bb36ae047c3
1 #!/usr/bin/env python
2
3 """
4 test matrix data transposition
5 """
6
7 import unittest
8 from tvii.transpose import transpose
9 from tvii.transpose import NotAMatrix
10
11
12 class TestTranspose(unittest.TestCase):
13
14 def test_transpose(self):
15 data = [[1.0, 0.0],
16 [2.0, -1.0],
17 [3.0, -2.0],
18 [4.0, -3.0]]
19 transposed = [[1.0, 2., 3., 4.],
20 [0., -1., -2., -3]]
21 assert (transpose(data) == transposed)
22
23 def test_not_a_matrix(self):
24
25 not_a_matrix = [[1,2,3],
26 [4,5,6],
27 [7, 8, 9, 10] # oops
28 ]
29 e = None
30 try:
31 transpose(not_a_matrix)
32 except NotAMatrix as e:
33 pass
34 assert e is not None
35 assert isinstance(e, NotAMatrix)
36
37 if __name__ == '__main__':
38 unittest.main()