コード例 #1
0
 def testGivenWhenThen0(self):
     eqs = EquationSystemBuilder().build()
     eqs.add(EquationBuilder.y_equals_x())
     a = EquationBuilder.one_equals_x()
     b = EquationBuilder().left_term(
         VariableBuilder().name('z').build()).right_term(
             VariableBuilder().name('x').build()).right_term(
                 VariableBuilder().name('y').build()).build()
     a.add_equation(EquationBuilder.one_equals_y())
     eqs.add(a)
     eqs.add(b)
     reduction_method = ReductionMethod()
     equation_system_solver = EquationSystemSolver(eqs, reduction_method)
     equation_system_solver.resolve()
     self.assertTrue(
         equation_system_solver.get_solution('x').equal(
             EquationBuilder.x_equals_1()))
     self.assertTrue(
         equation_system_solver.get_solution('y').equal(
             EquationBuilder.y_equals_1()))
     self.assertTrue(
         equation_system_solver.get_solution('z').equal(
             EquationBuilder().left_term(
                 VariableBuilder().name('z').build()).right_term(
                     ConstantBuilder().value(2).build()).build()))
コード例 #2
0
 def testEqualsEquationSystem3(self):
     eq_system = EquationSystemBuilder().build()
     eq_system.add(EquationBuilder.y_equals_1())
     eq_system.add(EquationBuilder.one_equals_x())
     eq_system2 = eq_system.clon()
     eq_system.add(EquationBuilder().left_variable('z', 1, 0).right_default_constant().build())
     self.assertNotEqual(eq_system, eq_system2)
コード例 #3
0
 def testGivenWhenThen1(self):
     eqs = EquationSystemBuilder().build()
     eqs.add(EquationBuilder.y_equals_x())
     a = EquationBuilder.one_equals_x()
     eqs.add(a)
     reduction_method = ReductionMethod()
     equation_system_solver = EquationSystemSolver(eqs, reduction_method)
     equation_system_solver.resolve()
     self.assertTrue(
         equation_system_solver.get_solution('x').equal(
             EquationBuilder.x_equals_1()))
     self.assertTrue(
         equation_system_solver.get_solution('y').equal(
             EquationBuilder.y_equals_1()))
コード例 #4
0
 def testEqualsEquationSystem(self):
     eq_system = EquationSystemBuilder().build()
     eq_system.add(EquationBuilder.one_equals_x())
     eq_system.add(EquationBuilder.y_equals_1())
     eq_system2 = eq_system.clon()
     self.assertEqual(eq_system, eq_system2)
コード例 #5
0
 def testReprEquationSyetem(self):
     eq_system = EquationSystemBuilder().build()
     eq_system.add(EquationBuilder.one_equals_x())
     eq_system.add(EquationBuilder.y_equals_1())
     self.assertEqual(repr(eq_system), 'EquationSystem([Equation(Expression([Constant(Fraction(1, 1))]), Expression([Variable(\'x\', Fraction(1, 1))])), Equation(Expression([Variable(\'y\', Fraction(1, 1))]), Expression([Constant(Fraction(1, 1))]))])')
コード例 #6
0
 def testStrEquationSystem(self):
     eq_system = EquationSystemBuilder().build()
     eq_system.add(EquationBuilder.one_equals_x())
     eq_system.add(EquationBuilder.y_equals_1())
     self.assertEqual(str(eq_system), '+1 = +x\n+y = +1')
コード例 #7
0
 def testGivenSystemWithTwoEquationsWithDifferentVariablesWhenRemoveOneVariableEquationThenSystemTheOtherVariableName(self):
     eq_system = EquationSystemBuilder().build()
     eq_system.add(EquationBuilder.one_equals_x())
     eq_system.add(EquationBuilder.y_equals_1())
     eq_system.remove(EquationBuilder.one_equals_x())
     self.assertEqual(eq_system.get_name_set(), {'y'})
コード例 #8
0
 def testGivenSystemWithOneEuationWhenRemoveThisEquationThenSystemHasNoNames(self):
     eq_system = EquationSystemBuilder().build()
     eq_system.add(EquationBuilder.one_equals_x())
     eq_system.remove(EquationBuilder.one_equals_x())
     self.assertEqual(eq_system.get_name_set(), set())
コード例 #9
0
 def testGivenEmptySystemWhenAddEquationWithXAndAddWithYThenXAndYarePresent(self):
     eq_system = EquationSystemBuilder().build()
     eq_system.add(EquationBuilder.one_equals_x())
     eq_system.add(EquationBuilder.y_equals_1())
     self.assertEqual(eq_system.get_name_set(), {'x', 'y'})
 def testGivenXEqualsOneWhenEqualsAgainstOneEqualsXThenTrueIsReturned(self):
     self.assertTrue(EquationBuilder.x_equals_1().equal(
         EquationBuilder.one_equals_x()))
 def testGivenOneEqualsXEquationWhenGetNameSetThenEmptyNameSetWithXOnlyIsReturned(
         self):
     equation = EquationBuilder.one_equals_x()
     self.assertEqual(equation.get_name_set(), {'x'})