<commit_before>import unittest

from symbolic import solvers
import symbolic 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_coefficients_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.Any)

        expected = [[-1,  2,  -3,  4],
                    [ 5, -6,   7, -8],
                    [ 9, 10, -11, 12]]

        obtained = solvers.expanded_coefficients_matrix(system)
        self.assertEqual(obtained, expected)

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.Any)
        result = solvers.solve(expr)
        self.assertEqual(result, {'x': 3236.0})

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

    def test_solve_system_of_3x3(self):
        system = sm.System([
            -x1  + 2*x2  - 3*x3 == 4,
            5*x1 - 6*x2  + 7*x3  == -8,<commit_msg>add test case for unsorted liner systems<commit_after>import unittest

from symbolic import solvers
import symbolic 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_expanded_coefficients_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.Any)

        expected = [[-1,  2,  -3,  4],
                    [ 5, -6,   7, -8],
                    [ 9, 10, -11, 12]]

        obtained = solvers.expanded_coefficients_matrix(system)
        self.assertEqual(obtained, expected)

    def test_unsorted_expanded_coefficients_matrix(self):
        """Should extract all coefficients of an unsorted system of linear
        equalities."""
        system = sm.System([
                      -x1 +  2*x2 ==  4 + 3*x3,
              7*x3 +  5*x1 - 6*x2 == -8,
            -11*x3 + 10*x2 + 9*x1 == 12]
                for x1, x2, x3 in sm.Any)

        expected = [[-1,  2,  -3,  4],
                    [ 5, -6,   7, -8],
                    [ 9, 10, -11, 12]]

        obtained = solvers.expanded_coefficients_matrix(system)
        self.assertEqual(obtained, expected)

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.Any)
        result = solvers.solve(expr)
        self.assertEqual(result, {'x': 3236.0})

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

    def test_solve_system_of_3x3(self):
        system = sm.System([
            -x1  + 2*x2  - 3*x3 == 4,
            5*x1 - 6*x2  + 7*x3  == -8,
{'fraction_non_alphanumeric': 0.13377067883628066, 'fraction_numerical': 0.06303479749001711, 'mean_word_length': 1.8236714975845412, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1961400', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1227, 'n_words': 287}