def testVariableIsolator(self):
     eq = EquationBuilder().left_constant(1).left_variable(
         'x', 2, 1).right_variable('x', 1, 2).build()
     eq.apply_operation(Equation.VariableIsolator('x'))
     isolated_eq = EquationBuilder().left_variable(
         'x', 1, 1).right_constant_fraction(-2, 3).build()
     self.assertEqual(eq, isolated_eq)
 def testVariableIsolatorWithMoreVariables(self):
     eq = EquationBuilder().left_constant(1).left_variable(
         'x', 2, 1).left_variable('y', 1, 1).right_variable('x', 1,
                                                            1).build()
     eq.apply_operation(Equation.VariableIsolator('x'))
     isolated_eq = EquationBuilder().left_variable(
         'x', 1, 1).right_constant(-1).right_variable('y', -1, 1).build()
     self.assertEqual(eq, isolated_eq)
 def testEquationSimplifyer(self):
     eq = EquationBuilder().left_constant(1).left_variable(
         'x', 2, 1).left_variable('x', 1,
                                  2).right_default_constant().build()
     eq.apply_operation(Equation.EquationSimplifyer())
     simplified_eq = EquationBuilder().left_constant(1).left_variable(
         'x', 5, 2).right_default_constant().build()
     self.assertEqual(eq, simplified_eq)
 def tesEquationApplier(self):
     # 1 + 2x + y = x
     eq = EquationBuilder().left_constant(1).left_variable(
         'x', 2, 1).left_variable('y', 1, 1).right_variable('x', 1,
                                                            1).build()
     # 1 +x -y = y +1  ->  x = y + y  ->  x = 2y
     eq2 = EquationBuilder().left_constant(1).left_variable(
         'x', 1, 1).left_variable('y', -1, 1).right_variable(
             'y', 1, 1).right_constant_fraction(1, 1).build()
     # eq: 1 + 4y + y = 2y
     eq.apply_operation(Equation.EquationApplier('x', eq2))
     resultant_eq = EquationBuilder().left_constant(1).left_variable(
         'y', 4, 1).left_variable('y', 1, 1).right_variable('y', 2,
                                                            1).build()
     self.assertEqual(eq, resultant_eq)