view tests/test_transpose.py @ 70:351fc97bb996

add error computation + test functions
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:22:44 -0800
parents 0bb36ae047c3
children 9d55e0299c3f
line wrap: on
line source

#!/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()