def test_numerical_integratior_trapezium_method_args_negative_sub_negative( self): def func(x): return x result = NumericalIntegrator().trapezium_method(-1, -2, func) self.assertEqual(round(result, 5), round(1.5, 5))
def test_numerical_integratior_simpson_method_args_negative_sub_positive( self): def func(x): return x result = NumericalIntegrator().simpson_method(-2, -1, func) self.assertEqual(round(result, 5), round(-1.5, 5))
def calculate(self): float_a = float(self.a) float_b = float(self.b) def func(x): return x if self.operation == Operation.TRAPEZIUM_METHOD: self.result = str( round( NumericalIntegrator().trapezium_method( float_a, float_b, func), 5)) elif self.operation == Operation.SIMPSON_METHOD: self.result = str( round( NumericalIntegrator().simpson_method( float_a, float_b, func), 5)) self.calculate_state = CalculateState.ENABLE
def calculate(self): self.logger.log('Button clicked') self.logger.log('Operation: {}'.format(self.operation)) float_a = float(self.a) float_b = float(self.b) def func(x): return x if self.operation == Operation.TRAPEZIUM_METHOD: self.result = str( round( NumericalIntegrator().trapezium_method( float_a, float_b, func), 5)) elif self.operation == Operation.SIMPSON_METHOD: self.result = str( round( NumericalIntegrator().simpson_method( float_a, float_b, func), 5)) self.calculate_state = CalculateState.ENABLE self.logger.log('Result: {}'.format(self.result))
def test_numerical_integratior_simpson_method_args_zero(self): def func(x): return x result = NumericalIntegrator().simpson_method(0, 0, func) self.assertEqual(result, 0)
def test_numerical_integratior_simpson_method_func_difficult(self): def func(x): return x * (x + 1) + 1 result = NumericalIntegrator().simpson_method(1, 2, func) self.assertEqual(round(result, 5), round(4.83333, 5))
def test_numerical_integratior_simpson_method_func_linear(self): def func(x): return x result = NumericalIntegrator().simpson_method(1, 2, func) self.assertEqual(round(result, 5), round(1.5, 5))
def test_numerical_integratior_can_create(self): numerical_integratior = NumericalIntegrator() self.assertTrue(isinstance(numerical_integratior, NumericalIntegrator))
def test_numerical_integratior_trapezium_method_func_zero(self): def func(x): return 0 result = NumericalIntegrator().trapezium_method(1, 2, func) self.assertEqual(result, 0)