view tests/test_transpose.py @ 71:9d55e0299c3f

fix scoping for python 3.6
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:19:30 -0800
parents 0bb36ae047c3
children
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:
            e = _e
        assert e is not None
        assert isinstance(e, NotAMatrix)

if __name__ == '__main__':
    unittest.main()