Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_append_row_to_empty_matrix(self):
        m = create_matrix(0, 0)
        m.append_row([1, 2])

        self.assertEqual(m.size.height, 1)
        self.assertEqual(m.size.width, 2)
        self.assertEqual(m.get(1, 1), 1)
        self.assertEqual(m.get(1, 2), 2)
Exemplo n.º 3
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)