changeset 69:0bb36ae047c3

test matrix transposition
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:16:16 -0800
parents 5916b04d0582
children 351fc97bb996
files tests/test_transpose.py
diffstat 1 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_transpose.py	Sun Dec 17 13:16:16 2017 -0800
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+"""
+test matrix data transposition
+"""
+
+import unittest
+from tvii.transpose import transpose
+from tvii.transpose import NotAMatrix
+
+
+class TestTranspose(unittest.TestCase):
+
+    def test_transpose(self):
+        data = [[1.0, 0.0],
+                [2.0, -1.0],
+                [3.0, -2.0],
+                [4.0, -3.0]]
+        transposed = [[1.0, 2., 3., 4.],
+                      [0., -1., -2., -3]]
+        assert (transpose(data) == transposed)
+
+    def test_not_a_matrix(self):
+
+        not_a_matrix = [[1,2,3],
+                        [4,5,6],
+                        [7, 8, 9, 10]  # oops
+                        ]
+        e = None
+        try:
+            transpose(not_a_matrix)
+        except NotAMatrix as e:
+            pass
+        assert e is not None
+        assert isinstance(e, NotAMatrix)
+
+if __name__ == '__main__':
+    unittest.main()