def testGivenEmptyEquationWhenAddEquationThenEquationIsEqualToAddedEquation( self): equation1 = EquationBuilder().build() equation2 = EquationBuilder.x_equals_1() equation1.add_equation(equation2) self.assertTrue(equation1.equal(equation2)) self.assertTrue(equation1 == equation2)
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()))
def testGivenDefaultEquationWhenMultiplyBy0ThenValue0IsObtainedInBothTerms( self): equation = EquationBuilder.x_equals_1() equation.multiply(0.0) self.assertEqual(equation.get_name_set(), set()) self.assertEqual(equation.get_value_constant(Side.left), 0.0) self.assertEqual(equation.get_value_constant(Side.right), 0.0)
def testGivenXIs1EquationAndXIs0WhenAskedForEqualityThenFalseIsReturned( self): equation1 = EquationBuilder.x_equals_0() equation2 = EquationBuilder.x_equals_1() self.assertFalse(equation1.equal(equation2)) self.assertFalse(equation1 == equation2) self.assertTrue(equation1 != equation2)
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()))
def testGivenEmptySystemWhenAddEquationWithXThenXisPresent(self): eq_system = EquationSystemBuilder().build() eq_system.add(EquationBuilder.x_equals_1()) self.assertEqual(eq_system.get_name_set(), {'x'})
def testGivenDefaultEquationWhenMultiplyBy1ThenSameEquationIsObtained( self): equation1 = EquationBuilder.x_equals_1() equation2 = EquationBuilder.x_equals_1() equation1.multiply(1.0) self.assertTrue(equation1.equal(equation2))
def testStrEquation(self): self.assertEqual(str(EquationBuilder.x_equals_1()), '+x = +1')
def testReprEquation(self): self.assertEqual( repr(EquationBuilder.x_equals_1()), 'Equation(Expression([Variable(\'x\', Fraction(1, 1))]), Expression([Constant(Fraction(1, 1))]))' )
def testGivenXEqualsOneEquationWhenInvertThenEquationOneEqualsXIsReturned( self): eq = EquationBuilder.x_equals_1() eq.invert() self.assertEqual(eq.get_value_constant(Side.left), 1.0)
def testGivenXEqualsOneEquationWhenClonThenEquationEqualsReturnsTrue(self): equation = EquationBuilder.x_equals_1() equation_clon = equation.clon() self.assertFalse(equation is equation_clon) self.assertTrue(equation.equal(equation_clon))
def testGivenXEqualsOneWhenEqualsAgainstYEqualsOneThenFalseIsReturned( self): self.assertFalse(EquationBuilder.x_equals_1().equal( EquationBuilder.y_equals_1()))
def testGivenXEqualsOneWhenEqualsAgainstXEqualsOneThenTrueIsReturned(self): self.assertTrue(EquationBuilder.x_equals_1().equal( EquationBuilder.x_equals_1()))
def testGivenXEqualsOneEquationWhenGetNameSetThenEmptyNameSetWithXOnlyIsReturned( self): equation = EquationBuilder.x_equals_1() self.assertEqual(equation.get_name_set(), {'x'})