import unittest

from symbolicmath import solvers
import symbolicmath as sm


class TestCoefficientMatrix(unittest.TestCase):
    @unittest.skip('Not yet implemented')
    def test_coefficient_matrix(self):
        system = sm.System(
            -x1  + 2*x2  - 3*x3  == 4  |
            5*x1 - 6*x2  + 7*x3  == -8 |
            9*x1 + 10*x2 - 11*x3 == 12
                for x1, x2, x3 in sm.Object)
        expected = sm.Object([
            [-1, 2, -3, 4],
            [5, -6, 7, -8],
            [9, 10, -11, 12]])
        obtained = solvers.extract_coefficients(system)
        self.assertEqual(obtained, expected)


class TestSolver(unittest.TestCase):
    def solve_single_variable_linear_equation(self):
        expr = sm.System(
            x - 2*x + 5*x - 46*(235-24) == x + 2 for x in sm.Object)
        result = solvers.solve(expr)
        self.assertEqual(result, {'x': 3236.0})


if __name__ == '__main__':
    unittest.main()

import unittest

from symbolicmath import solvers
import symbolicmath as sm


class TestCoefficientMatrix(unittest.TestCase):
    def test_extract_independent_term(self):
        expr = '9*x1 + 10*x2 - 11*x3 + 12'
        obtained = solvers.extract_independent_term(expr, ['x1', 'x2', 'x3'])
        expected = 12
        self.assertEqual(obtained, expected)

    def test_coefficient_matrix(self):
        system = sm.System([
            -x1  + 2*x2  - 3*x3 == 4,
            5*x1 - 6*x2  + 7*x3  == -8,
            9*x1 + 10*x2 - 11*x3 == 12]
                for x1, x2, x3 in sm.Object)

        expected = sm.Object([
            [-1, 2, -3, 4],
            [5, -6, 7, -8],
            [9, 10, -11, 12]])

        obtained = solvers.extract_coefficients(system)
        self.assertEqual(obtained._array, expected._array)


class TestSolver(unittest.TestCase):
    def test_solve_single_variable_linear_equation(self):
        expr = sm.System(
            x - 2*x + 5*x - 46*(235-24) == x + 2 for x in sm.Object)
        result = solvers.solve(expr)
        self.assertEqual(result, {'x': 3236.0})

    def test_cero_equation(self):
        expr = sm.System(
            0 == x + 4 for x in sm.Object)
        result = solvers.solve(expr)
        self.assertEqual(result, {'x': -4.0})

if __name__ == '__main__':
    unittest.main()

add test case for the extract_independent_term() function, and use the new API in test_coefficient_matrix() test function