Beispiel #1
0
 def test_append_column(self):
     m = create_square_matrix(2)
     m.append_column(parse_matrix("1 2").transpose())
     self.assertEqual(m.size.height, 2)
     self.assertEqual(m.size.width, 3)
     self.assertEqual(m.get(1, 3), 1)
     self.assertEqual(m.get(2, 3), 2)
Beispiel #2
0
    def test_copy(self):
        a = parse_matrix("1 2;3 4")
        b = a.copy()
        self.assertEqual(b, a)

        b.set(1, 1, 3)
        self.assertNotEqual(b, a)
Beispiel #3
0
    def test_append_column_to_empty_matrix(self):
        m = create_matrix(0, 0)
        m.append_column(parse_matrix("1;2"))

        self.assertEqual(m.size.height, 2)
        self.assertEqual(m.size.width, 1)
        self.assertEqual(m.get(1, 1), 1)
        self.assertEqual(m.get(2, 1), 2)
Beispiel #4
0
    def test_parse_1x3_matrix(self):
        m = parse_matrix("5 4 3")

        self.assertEqual(m.size.height, 1)
        self.assertEqual(m.size.width, 3)
        self.assertEqual(m.get(1, 1), 5)
        self.assertEqual(m.get(1, 2), 4)
        self.assertEqual(m.get(1, 3), 3)
Beispiel #5
0
    def test_parse_2x2_matrix(self):
        m = parse_matrix("1 2;3 4")

        self.assertEqual(m.size.height, 2)
        self.assertEqual(m.size.width, 2)
        self.assertEqual(m.get(1, 1), 1)
        self.assertEqual(m.get(1, 2), 2)
        self.assertEqual(m.get(2, 1), 3)
        self.assertEqual(m.get(2, 2), 4)
Beispiel #6
0
 def test_mxn_nxm_multiplication(self):
     a = parse_matrix("1 2;3 4")
     b = parse_matrix("5 6;7 8")
     c = parse_matrix("19 22;43 50")
     self.assertEqual(c, a * b)
Beispiel #7
0
 def test_diagonal_matrix(self):
     a = parse_matrix("1 2 3;4 5 6;7 8 9")
     expected_matrix = parse_matrix("1 0 0;0 5 0;0 0 9")
     self.assertEqual(expected_matrix, a.diagonal_matrix())
Beispiel #8
0
 def test_get_column(self):
     self.assertEqual(parse_matrix("2;4"), parse_matrix("1 2;3 4").get_column(2))
Beispiel #9
0
 def test_multiplication_with_identity_matrix(self):
     # a * I = a
     a = parse_matrix("1 2 3;4 5 6;7 8 9")
     I = create_identity_matrix(3)
     self.assertEqual(a, a * I)
     self.assertEqual(a, I * a)
Beispiel #10
0
 def test_multiplication_with_scalar_commutative_law(self):
     a = parse_matrix("1 2;3 4")
     self.assertEqual(a * 5, 5 * a)
Beispiel #11
0
 def test_multiplication_commutative_law(self):
     a = parse_matrix("1 2;3 4")
     b = parse_matrix("5 6;7 8")
     self.assertNotEqual(a * b, b * a)
Beispiel #12
0
 def test_subtraction_from_right(self):
     # a-b=c
     a = parse_matrix("1 2;3 4")
     b = parse_matrix("5 6;7 8")
     c = parse_matrix("-4 -4;-4 -4")
     self.assertEqual(c, a - b)
Beispiel #13
0
 def add():
     parse_matrix("1 2;3 4") + parse_matrix("1 2 3;4 5 6")
Beispiel #14
0
 def add():
     parse_matrix("1 2;3 4") + 5
Beispiel #15
0
 def test_addition_commutative_law(self):
     # a+b=b+a
     a = parse_matrix("1 2;3 4")
     b = parse_matrix("5 6;7 8")
     self.assertEqual(a + b, b + a)
Beispiel #16
0
 def test_addition(self):
     # a+b=c
     a = parse_matrix("1 2;3 4")
     b = parse_matrix("5 6;7 8")
     c = parse_matrix("6 8;10 12")
     self.assertEqual(c, a + b)
Beispiel #17
0
 def test_axn_nxb_multiplication(self):
     a = parse_matrix("1 2 3;4 5 6")
     b = parse_matrix("7 8 9 10;11 12 13 14;15 16 17 18")
     c = parse_matrix("74 80 86 92;173 188 203 218")
     self.assertEqual(c, a * b)
Beispiel #18
0
 def test_subtraction_from_left(self):
     # b-a=c
     b = parse_matrix("5 6;7 8")
     a = parse_matrix("1 2;3 4")
     c = parse_matrix("4 4;4 4")
     self.assertEqual(c, b - a)
Beispiel #19
0
 def multiply():
     parse_matrix("1 2 3") * parse_matrix("1 2 3")
Beispiel #20
0
 def test_subtraction_is_not_commutative(self):
     # a-b!=b-a
     a = parse_matrix("1 2;3 4")
     b = parse_matrix("5 6;7 8")
     self.assertNotEqual(a - b, b - a)
Beispiel #21
0
 def test_multiplication_with_scalar(self):
     a = parse_matrix("1 2;3 4")
     self.assertEqual(parse_matrix("5 10;15 20"), a * 5)
Beispiel #22
0
 def sub():
     parse_matrix("1 2;3 4") - 5
Beispiel #23
0
 def multiply():
     parse_matrix("1") * "2"
Beispiel #24
0
 def sub():
     parse_matrix("1 2;3 4") - parse_matrix("1 2 3;4 5 6")
Beispiel #25
0
 def test_get_row(self):
     self.assertEqual(parse_matrix("3 4"), parse_matrix("1 2;3 4").get_row(2))
Beispiel #26
0
 def test_lower_triangle(self):
     a = parse_matrix("1 2 3;4 5 6;7 8 9")
     expected_matrix = parse_matrix("0 0 0;4 0 0;7 8 0")
     self.assertEqual(expected_matrix, a.lower_triangle())
Beispiel #27
0
 def test_append_column_with_wrong_height(self):
     m = create_square_matrix(2)
     self.assertRaises(ValueError, m.append_column, parse_matrix("1;2;3"))
Beispiel #28
0
 def test_1xn_nx1_multiplication(self):
     a = parse_matrix("1 2 3")
     b = parse_matrix("4 5 6").transpose()
     c = parse_matrix("32")
     self.assertEqual(c, a * b)
Beispiel #29
0
 def test_transpose_row(self):
     self.assertEqual(parse_matrix("1;2;3"), parse_matrix("1 2 3").transpose())
Beispiel #30
0
    def test_parse_1x1_matrix(self):
        m = parse_matrix("5")

        self.assertEqual(m.size.height, 1)
        self.assertEqual(m.size.width, 1)
        self.assertEqual(m.get(1, 1), 5)