Beispiel #1
0
 def testGivenExpressionWithTwoVariablesWithInverseValuesWhenSimplifyThenExpressionWithNoVariablesAndConstantWithValue0IsObtained(
         self):
     variable1 = VariableBuilder().build()
     variable2 = variable1.clon()
     variable2.multiply(-1.0)
     expression = ExpressionBuilder().term(variable1).term(
         variable2).build()
     expression.simplify_variable(variable1.name)
     self.assertEqual(expression.get_value_constant(), 0.0)
     self.assertEqual(expression.get_value_variable(variable1.name), 0.0)
 def testGivenEmptyEquationWhenAddTermThenTermIsAddedInBothSides(self):
     equation = EquationBuilder().build()
     term = VariableBuilder().build()
     inverse_term = term.clon()
     inverse_term.multiply(-1.0)
     equation.add(term)
     self.assertEqual(equation.get_name_set(), {term.name})
     equation.add_side(Side.left, inverse_term)
     equation.simplify_variable(Side.left, term.name)
     self.assertEqual(equation.get_value_constant(Side.left), 0.0)
     self.assertEqual(equation.get_name_set(), {term.name})
     equation.add_side(Side.right, inverse_term)
     equation.simplify_variable(Side.right, term.name)
     self.assertEqual(equation.get_value_constant(Side.right), 0.0)
     self.assertEqual(equation.get_name_set(), set())
Beispiel #3
0
 def testGivenExpressionWithTwoVariablesWithSameNameWhenGetValueNameThenNotSimplifiedIsRaised(
         self):
     variable = VariableBuilder().name('x').build()
     expression = ExpressionBuilder().term(variable).term(
         variable.clon()).build()
     self.assertRaises(NotSimplified, expression.get_value_variable, 'x')
Beispiel #4
0
 def testGivenExpressionWithTwoVariablesWithSameNameWhenGetNameSetThenSetWithVariablesNameIsReturned(
         self):
     variable = VariableBuilder().name('x').build()
     expression = ExpressionBuilder().term(variable).term(
         variable.clon()).build()
     self.assertEqual(expression.get_name_set(), {variable.name})
 def testClon(self):
     variable1 = VariableBuilder().build()
     variable2 = variable1.clon()
     self.assertFalse(variable1 is variable2)
     self.assertTrue(variable1.equal(variable2))