def test_generate_x_array(self): self.assertEqual(Polynomial.generate_x_array(0, 10, 6), [0, 2, 4, 6, 8, 10]) self.assertEqual(Polynomial.generate_x_array(0, 20, 10), [ 0, 2.2222222222222223, 4.444444444444445, 6.666666666666667, 8.88888888888889, 11.11111111111111, 13.333333333333334, 15.555555555555557, 17.77777777777778, 20 ])
def test_calculate_area(self): function_1 = Polynomial.from_string("x^3+5") self.assertEqual(function_1.calculate_area(-5, 9), 1829.3248196000754) # -5,9 self.assertEqual(function_1.calculate_area(-0, 0), 0) # 0,0 function_2 = Polynomial.from_string("-3x^3-3x^2-10x+45") self.assertEqual(function_2.calculate_area(-10, -5), 6756.25) # -10,-5 self.assertEqual(function_2.calculate_area(5, 10), 8056.25) # 5,10
def test_tangent(self): function_1 = Polynomial.from_string("2x^2") self.assertEqual(str(function_1.calculate_tangent(0)), "0") # tangent at x=0 function_2 = Polynomial.from_string("-3x^3-3x^2-10x+45") self.assertEqual(str(function_2.calculate_tangent(-10)), "-850x - 5655") # tangent at x=-10 function_3 = Polynomial.from_string("x^3+3x^2-5x-90") self.assertEqual(str(function_3.calculate_tangent(-5)), "40x + 85") # tangent at x=-5
def test_repr(self): function = Polynomial.from_string("x^2") self.assertEqual(str(function.__repr__()), "Polynomial((1, 0, 0))")
def test_subtraction(self): function_1 = Polynomial.from_string("x^3+3x^2-5x-90") function_2 = Polynomial.from_string("-3x^3-3x^2-10x+45") self.assertEqual(str(function_1 - function_2), "4x^3 + 6x^2 + 5x - 135")
def test_extrempoints(self): for index, group in enumerate(testing): function = Polynomial.from_string(group[0]) self.assertEqual(function.get_extreme_points(), testing[index][7]) # extrempoints
def test_addition(self): function_1 = Polynomial.from_string("x^3+3x^2-5x-90") function_2 = Polynomial.from_string("-3x^3-3x^2-10x+45") self.assertEqual(str(function_1 + function_2), "-2x^3 - 15x - 45")
def test_call_zero(self): for index, group in enumerate(testing): function = Polynomial.from_string(group[0]) self.assertEqual(function(0), testing[index][5]) # f(0)
def test_call_neg_ten(self): for index, group in enumerate(testing): function = Polynomial.from_string(group[0]) self.assertEqual(function(-10), testing[index][6]) # f(-10)
def test_zeros(self): for index, group in enumerate(testing): function = Polynomial.from_string(group[0]) self.assertEqual(str(function.find_all_zero()), testing[index][4]) # zeros
def test_integral(self): for index, group in enumerate(testing): function = Polynomial.from_string(group[0]) self.assertEqual(str(function.integral()), testing[index][3]) # Integral
def test_derivative(self): for index, group in enumerate(testing): function = Polynomial.from_string(group[0]) self.assertEqual(str(function.derivative()), testing[index][2]) # derivative
def test_degree(self): for index, function in enumerate(testing): function = Polynomial.from_string(function[0]) self.assertEqual(function.degree, testing[index][1]) # degree
def test_len(self): function = Polynomial.from_string("x^2") self.assertEqual(function.__len__(), 3)