Esempio n. 1
0
 def test_create_matrix(self):
     assert all(
         Matrix.create_matrix(3, 2, lambda i, j: j + i * 2)[x][y] == (y +
                                                                      x * 2)
         for y in range(2) for x in range(3))
     assert Matrix.create_matrix(3, 0).sizes == (3, 0)
     assert Matrix.create_matrix(0, 3).sizes == (0, 0)
Esempio n. 2
0
 def test_transposed(self):
     assert Vector([1, 2, 3], transposed=True).transposed
     assert not Vector([1, 2, 3]).transposed
     assert Vector(Matrix([[1, 2, 3]])).transposed
     assert not Vector(Matrix([[1], [2], [3]])).transposed
     assert Vector([], transposed=True).transposed
     assert not Vector([]).transposed
Esempio n. 3
0
 def test_get(self):
     assert all(
         Matrix([[(0, 0), (0, 1)], [(1, 0), (1,
                                             1)], [(2,
                                                    0), (2,
                                                         1)]])[x][y] == (x,
                                                                         y)
         for y in range(2) for x in range(3))
Esempio n. 4
0
 def test_repr(self):
     assert repr(Matrix.create_matrix(2, 2)) == '\n|0 0|\n|0 0|'
Esempio n. 5
0
 def test_div(self):
     assert Matrix.create_matrix(
         2, 3, lambda i, j: 2) / 2 == Matrix.create_matrix(
             2, 3, lambda i, j: 1)
Esempio n. 6
0
 def test_mul(self):
     assert Matrix([[1, 2], [3, 4], [5, 6]]) * Matrix(
         [[-1, -1, -1], [1, 1, 1]]) == Matrix([[1, 1, 1], [1, 1, 1],
                                               [1, 1, 1]])
     with raises(ArithmeticError):
         Matrix.create_matrix(3, 1) * Matrix.create_matrix(3, 1)
Esempio n. 7
0
 def test_constructor(self):
     Matrix([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
     with raises(ValueError):
         Matrix([[0, 0, 0], [0, 0], [0, 0, 0]])
     Matrix([])
     Matrix([[], [], []])
Esempio n. 8
0
 def test_iter(self):
     assert tuple(vector[0]
                  for vector in Matrix([[0], [1], [2]])) == (0, 1, 2)
Esempio n. 9
0
 def test_invert(self):
     assert ~Matrix.create_matrix(
         3, 2, lambda i, j: j + i * 2) == Matrix.create_matrix(
             2, 3, lambda i, j: i + j * 2)
Esempio n. 10
0
 def test_neg(self):
     assert -Matrix.create_matrix(3, 3,
                                  lambda i, j: 1) == Matrix.create_matrix(
                                      3, 3, lambda i, j: -1)
Esempio n. 11
0
 def test_add(self):
     assert Matrix.create_matrix(3, 3) + Matrix.create_matrix(
         3, 3, lambda i, j: 1) == Matrix.create_matrix(
             3, 3, lambda i, j: 1)
Esempio n. 12
0
 def test_equal(self):
     assert Matrix.create_matrix(3, 3) == Matrix.create_matrix(3, 3)
Esempio n. 13
0
 def test_call(self):
     assert tuple(Matrix.create_matrix(3, 1,
                                       lambda i, j: i)(0)) == (0, 1, 2)
Esempio n. 14
0
 def test_matrix(self):
     assert all(
         Matrix.create_matrix(2, 3, lambda i, j: j + i * 3).matrix[x][y] ==
         (y + x * 3) for y in range(3) for x in range(2))
Esempio n. 15
0
 def test_constructor(self):
     Vector([1, 2, 3])
     Vector([])
     with raises(ValueError):
         Vector(Matrix([[1, 2, 3], [1, 2, 3]]))
Esempio n. 16
0
 def test_sub(self):
     assert Matrix.create_matrix(
         3, 3, lambda i, j: 1) - Matrix.create_matrix(
             3, 3, lambda i, j: 1) == Matrix.create_matrix(3, 3)
Esempio n. 17
0
 def test_mn(self):
     assert Matrix([[0, 0], [0, 0], [0, 0]]).sizes == (3, 2)
     assert Matrix([]).sizes == (0, 0)
     assert Matrix([[], [], []]).sizes == (3, 0)