Example #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)
Example #2
0
 def test_append_row(self):
     m = create_square_matrix(2)
     m.append_row([1, 2])
     self.assertEqual(m.size.height, 3)
     self.assertEqual(m.size.width, 2)
     self.assertEqual(m.get(3, 1), 1)
     self.assertEqual(m.get(3, 2), 2)
Example #3
0
    def test_set_values(self):
        m = create_square_matrix(2)
        m.set(1, 1, 1)
        m.set(1, 2, 2)
        m.set(2, 1, 3)
        m.set(2, 2, 4)

        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)
Example #4
0
    def parse(self):
        with open(self.filePath) as f:
            file_content = f.readlines()

        # First section: Amount of equations
        self.numberOfEquations = int(file_content[0])

        # Second section: Coefficient matrix
        self.coefficients = create_square_matrix(self.numberOfEquations)
        for row in range(0, self.numberOfEquations):
            splitted_row = file_content[row + 1].split()
            for column in range(0, self.numberOfEquations):
                coefficient = int(splitted_row[column])
                self.coefficients.set(row + 1, column + 1, coefficient)

        # Third section: Result matrix
        self.results = create_matrix(self.numberOfEquations, 1)
        for row in range(0, self.numberOfEquations):
            result = int(file_content[row + 4])
            self.results.set(row + 1, 1, result)
Example #5
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"))
Example #6
0
 def test_append_row_with_wrong_width(self):
     m = create_square_matrix(2)
     self.assertRaises(ValueError, m.append_row, [1, 2, 3])
Example #7
0
 def test_set_with_index_above_size(self):
     self.assertRaises(ValueError, create_square_matrix(2).set, 3, 1, -1)
     self.assertRaises(ValueError, create_square_matrix(2).set, 1, 3, -1)
     self.assertRaises(ValueError, create_square_matrix(2).set, 3, 3, -1)
Example #8
0
 def test_set_with_index_below_one(self):
     self.assertRaises(ValueError, create_square_matrix(2).set, 0, 1, -1)
     self.assertRaises(ValueError, create_square_matrix(2).set, 1, 0, -1)
     self.assertRaises(ValueError, create_square_matrix(2).set, 0, 0, -1)
Example #9
0
    def test_initialized_with_zero(self):
        m = create_square_matrix(3)

        def check_is_zero(row, column, value): self.assertEqual(0, value)

        m.on_every_element(check_is_zero)