def computing(self):
     first_poly = Polynomial.from_string(self.first_poly)
     second_poly = Polynomial.from_string(self.second_poly)
     if first_poly and second_poly:
         if self.operation == '+':
             self.result = str(first_poly + second_poly)
         elif self.operation == '-':
             self.result = str(first_poly - second_poly)
         elif self.operation == '*':
             self.result = str(first_poly * second_poly)
     else:
         self.result = 'Coeff has no type int'
예제 #2
0
 def test_eq_poly_with_zero(self):
     self.assertTrue(
         Polynomial([0, 1, 2, 3, 4]) == Polynomial([1, 2, 3, 4]))
예제 #3
0
 def test_sub_poly_and_poly(self):
     self.assertEqual(Polynomial([-4, -4, -4, -4]),
                      Polynomial([1, 2, 3]) - Polynomial([4, 5, 6, 7]))
예제 #4
0
 def test_sub_fail_poly_and_incorrect_type(self):
     with self.assertRaises(TypeError):
         Polynomial([1, 2, 3]) - 'str'
예제 #5
0
 def test_sub_number_and_poly(self):
     self.assertEqual(Polynomial([-1, -2, -2]), 1 - Polynomial([1, 2, 3]))
예제 #6
0
 def test_sum_poly_and_poly_with_check_zero(self):
     self.assertEqual(Polynomial([1, 0]),
                      Polynomial([1, 2, 3]) + Polynomial([-1, -1, -3]))
예제 #7
0
 def test_sum_fail_incorrect_type_and_poly(self):
     with self.assertRaises(TypeError):
         'str' + Polynomial([1, 2, 3])
예제 #8
0
 def test_sum_poly_and_number(self):
     self.assertEqual(Polynomial([1, 2, 4]), Polynomial([1, 2, 3]) + 1)
예제 #9
0
 def test_from_string(self):
     self.assertEqual(Polynomial([1, 2, 3]),
                      Polynomial.from_string('1,2,3'))
예제 #10
0
 def test_str_with_zeros(self):
     self.assertEqual('x^2 + 2x + 3', str(Polynomial([0, 0, 1, 2, 3])))
예제 #11
0
 def test_str(self):
     self.assertEqual('x^2 + x + 1', str(Polynomial([1, 1, 1])))
예제 #12
0
 def test_repr_with_zeros(self):
     self.assertEqual('Polynomial([1, 2, 3])', repr(Polynomial([0, 1, 2,
                                                                3])))
예제 #13
0
 def test_repr(self):
     self.assertEqual('Polynomial([1, 2, 3])', repr(Polynomial([1, 2, 3])))
예제 #14
0
 def test_eq_fail_incorrect_type(self):
     with self.assertRaises(TypeError):
         Polynomial([0, 1, 4, 0, -8]) == 'test'
예제 #15
0
 def test_not_eq_poly(self):
     self.assertFalse(Polynomial([1, 2, 3, 4]) == Polynomial([1, 2, 3, 5]))
예제 #16
0
 def test_init_fails_on_incorrect_coeffs_type_string(self):
     with self.assertRaises(TypeError):
         Polynomial(['42453', '24'])
예제 #17
0
 def test_init_fails_on_incorrect_coeffs_type_float(self):
     with self.assertRaises(TypeError):
         Polynomial([2.0, 6.1])
예제 #18
0
 def test_error_val(self):
     self.assertEqual(False, Polynomial.from_string('1,2,a'))
예제 #19
0
 def test_sum_number_and_poly(self):
     self.assertEqual(Polynomial([1, 2, 4]), 1 + Polynomial([1, 2, 3]))
예제 #20
0
 def test_init_param_polynomial(self):
     pol1 = Polynomial([1, 2, 3])
     pol2 = Polynomial(pol1)
     self.assertEqual(pol1.coeffs, pol2.coeffs)
예제 #21
0
 def test_sum_poly_and_poly(self):
     self.assertEqual(Polynomial([4, 6, 8, 10]),
                      Polynomial([1, 2, 3]) + Polynomial([4, 5, 6, 7]))
예제 #22
0
 def test_init_with_start_zeros_in_param(self):
     self.assertEqual([1, 2, -4], Polynomial((0, 0, 0, 1, 2, -4)).coeffs)
예제 #23
0
 def test_sub_poly_and_number(self):
     self.assertEqual(Polynomial([1, 2, 2]), Polynomial([1, 2, 3]) - 1)
예제 #24
0
 def test_init_param_zero(self):
     self.assertEqual([0], Polynomial([0]).coeffs)
예제 #25
0
 def test_sub_poly_and_zero(self):
     self.assertEqual(Polynomial([1, 2, 3]), Polynomial([1, 2, 3]) - 0)
예제 #26
0
 def test_init_param_only_zeros(self):
     self.assertEqual([0], Polynomial([0, 0, 0]).coeffs)
예제 #27
0
 def test_init_param_list(self):
     _list = list([1, 2, 3])
     self.assertEqual(_list, Polynomial(_list).coeffs)
예제 #28
0
 def test_init_fails_on_empty_param(self):
     with self.assertRaises(AttributeError):
         Polynomial([])
예제 #29
0
 def test_sub_poly_and_poly_with_check_zero(self):
     self.assertEqual(Polynomial([1, 0]),
                      Polynomial([1, 2, 3]) - Polynomial([1, 1, 3]))
예제 #30
0
 def test_init_fails_on_incorrect_input_param(self):
     with self.assertRaises(TypeError):
         Polynomial(1)