view 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
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()