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)
def test_repr(self): assert repr(Matrix.create_matrix(2, 2)) == '\n|0 0|\n|0 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)
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)
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)
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)
def test_neg(self): assert -Matrix.create_matrix(3, 3, lambda i, j: 1) == Matrix.create_matrix( 3, 3, lambda i, j: -1)
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)
def test_equal(self): assert Matrix.create_matrix(3, 3) == Matrix.create_matrix(3, 3)
def test_call(self): assert tuple(Matrix.create_matrix(3, 1, lambda i, j: i)(0)) == (0, 1, 2)
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))