56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
|
from unittest import TestCase
|
||
|
|
||
|
import numpy
|
||
|
|
||
|
from matrix import Matrix
|
||
|
|
||
|
|
||
|
class TestMatrix(TestCase):
|
||
|
def test_should_create_matrix_from_numpy_array_with_shape_3_2(self):
|
||
|
data = numpy.array([[0, 1], [2, 3], [4, 5]])
|
||
|
m = Matrix(data)
|
||
|
|
||
|
actual_shape = m.shape()
|
||
|
expected_shape = (3, 2)
|
||
|
self.assertEqual(expected_shape, actual_shape)
|
||
|
|
||
|
actual_data = m.get_data()
|
||
|
expected_data = [[0, 1], [2, 3], [4, 5]]
|
||
|
self.assertEqual(expected_data, actual_data)
|
||
|
|
||
|
def test_should_create_matrix_from_numpy_array_with_shape_1_3(self):
|
||
|
data = numpy.array([[0, 1, 2]])
|
||
|
m = Matrix(data)
|
||
|
|
||
|
actual_shape = m.shape()
|
||
|
expected_shape = (1, 3)
|
||
|
self.assertEqual(expected_shape, actual_shape)
|
||
|
|
||
|
actual_data = m.get_data()
|
||
|
expected_data = [[0, 1, 2]]
|
||
|
self.assertEqual(expected_data, actual_data)
|
||
|
|
||
|
def test_should_create_vectorlike_matrix_from_numpy_array_with_shape_3_1(self):
|
||
|
data = numpy.array([0, 1, 2])
|
||
|
m = Matrix(data)
|
||
|
|
||
|
actual_shape = m.shape()
|
||
|
expected_shape = (3, 1)
|
||
|
self.assertEqual(expected_shape, actual_shape)
|
||
|
|
||
|
actual_data = m.get_data()
|
||
|
expected_data = [0, 1, 2]
|
||
|
self.assertEqual(expected_data, actual_data)
|
||
|
|
||
|
def test_should_create_matrix_from_list_with_shape_2_2(self):
|
||
|
data = [0, 1, 2, 3]
|
||
|
m = Matrix(data, shape=(2, 2))
|
||
|
|
||
|
actual_shape = m.shape()
|
||
|
expected_shape = (2, 2)
|
||
|
self.assertEqual(expected_shape, actual_shape)
|
||
|
|
||
|
actual_data = m.get_data()
|
||
|
expected_data = [[0, 1], [2, 3]]
|
||
|
self.assertEqual(expected_data, actual_data)
|