示例#1
0
 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
     ])
示例#2
0
    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
示例#3
0
    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
示例#4
0
 def test_repr(self):
     function = Polynomial.from_string("x^2")
     self.assertEqual(str(function.__repr__()), "Polynomial((1, 0, 0))")
示例#5
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")
示例#6
0
 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
示例#7
0
 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")
示例#8
0
 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)
示例#9
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)
示例#10
0
 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
示例#11
0
 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
示例#12
0
 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
示例#13
0
 def test_degree(self):
     for index, function in enumerate(testing):
         function = Polynomial.from_string(function[0])
         self.assertEqual(function.degree, testing[index][1])  # degree
示例#14
0
 def test_len(self):
     function = Polynomial.from_string("x^2")
     self.assertEqual(function.__len__(), 3)