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())
def testGivenEquationSameConstantTwiceAtRightWhenSimplifyThenConstantIsSimplified( self): term = ConstantBuilder().build() equation = EquationBuilder().right_term(term).right_term(term).build() equation.simplify_constant(Side.right) self.assertEqual(equation.get_value_constant(Side.right), 2 * term.value)
def testGivenEmptyEquationWhenAddConstantSideRightThenItIsAddedInRightSide( self): equation = EquationBuilder().build() term = ConstantBuilder().value(1.0).build() equation.add_side(Side.right, term) self.assertEqual(equation.get_value_constant(Side.right), term.value)
def testGivenEmptyEquationWhenAddConstantThenItIsAddedInBothSides(self): equation = EquationBuilder().build() term = ConstantBuilder().build() equation.add(term) self.assertEqual(equation.get_value_constant(Side.left), term.value) self.assertEqual(equation.get_value_constant(Side.right), term.value)
def testGivenEquationWithOneConstantAtRightWhenGetValueThenConstantValueIsReturned( self): constant = ConstantBuilder().build() equation = EquationBuilder().right_term(constant).build() self.assertEqual(equation.get_value_constant(Side.right), constant.value)
def testGivenEmptyEquationWhenGetValueSideThenReturns0(self): equation = EquationBuilder().build() self.assertEqual(equation.get_value_constant(Side.left), 0) self.assertEqual(equation.get_value_constant(Side.right), 0)