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'
Ejemplo n.º 2
0
 def test_eq_poly_with_zero(self):
     self.assertTrue(
         Polynomial([0, 1, 2, 3, 4]) == Polynomial([1, 2, 3, 4]))
Ejemplo n.º 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]))
Ejemplo n.º 4
0
 def test_sub_fail_poly_and_incorrect_type(self):
     with self.assertRaises(TypeError):
         Polynomial([1, 2, 3]) - 'str'
Ejemplo n.º 5
0
 def test_sub_number_and_poly(self):
     self.assertEqual(Polynomial([-1, -2, -2]), 1 - Polynomial([1, 2, 3]))
Ejemplo n.º 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]))
Ejemplo n.º 7
0
 def test_sum_fail_incorrect_type_and_poly(self):
     with self.assertRaises(TypeError):
         'str' + Polynomial([1, 2, 3])
Ejemplo n.º 8
0
 def test_sum_poly_and_number(self):
     self.assertEqual(Polynomial([1, 2, 4]), Polynomial([1, 2, 3]) + 1)
Ejemplo n.º 9
0
 def test_from_string(self):
     self.assertEqual(Polynomial([1, 2, 3]),
                      Polynomial.from_string('1,2,3'))
Ejemplo n.º 10
0
 def test_str_with_zeros(self):
     self.assertEqual('x^2 + 2x + 3', str(Polynomial([0, 0, 1, 2, 3])))
Ejemplo n.º 11
0
 def test_str(self):
     self.assertEqual('x^2 + x + 1', str(Polynomial([1, 1, 1])))
Ejemplo n.º 12
0
 def test_repr_with_zeros(self):
     self.assertEqual('Polynomial([1, 2, 3])', repr(Polynomial([0, 1, 2,
                                                                3])))
Ejemplo n.º 13
0
 def test_repr(self):
     self.assertEqual('Polynomial([1, 2, 3])', repr(Polynomial([1, 2, 3])))
Ejemplo n.º 14
0
 def test_eq_fail_incorrect_type(self):
     with self.assertRaises(TypeError):
         Polynomial([0, 1, 4, 0, -8]) == 'test'
Ejemplo n.º 15
0
 def test_not_eq_poly(self):
     self.assertFalse(Polynomial([1, 2, 3, 4]) == Polynomial([1, 2, 3, 5]))
Ejemplo n.º 16
0
 def test_init_fails_on_incorrect_coeffs_type_string(self):
     with self.assertRaises(TypeError):
         Polynomial(['42453', '24'])
Ejemplo n.º 17
0
 def test_init_fails_on_incorrect_coeffs_type_float(self):
     with self.assertRaises(TypeError):
         Polynomial([2.0, 6.1])
Ejemplo n.º 18
0
 def test_error_val(self):
     self.assertEqual(False, Polynomial.from_string('1,2,a'))
Ejemplo n.º 19
0
 def test_sum_number_and_poly(self):
     self.assertEqual(Polynomial([1, 2, 4]), 1 + Polynomial([1, 2, 3]))
Ejemplo n.º 20
0
 def test_init_param_polynomial(self):
     pol1 = Polynomial([1, 2, 3])
     pol2 = Polynomial(pol1)
     self.assertEqual(pol1.coeffs, pol2.coeffs)
Ejemplo n.º 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]))
Ejemplo n.º 22
0
 def test_init_with_start_zeros_in_param(self):
     self.assertEqual([1, 2, -4], Polynomial((0, 0, 0, 1, 2, -4)).coeffs)
Ejemplo n.º 23
0
 def test_sub_poly_and_number(self):
     self.assertEqual(Polynomial([1, 2, 2]), Polynomial([1, 2, 3]) - 1)
Ejemplo n.º 24
0
 def test_init_param_zero(self):
     self.assertEqual([0], Polynomial([0]).coeffs)
Ejemplo n.º 25
0
 def test_sub_poly_and_zero(self):
     self.assertEqual(Polynomial([1, 2, 3]), Polynomial([1, 2, 3]) - 0)
Ejemplo n.º 26
0
 def test_init_param_only_zeros(self):
     self.assertEqual([0], Polynomial([0, 0, 0]).coeffs)
Ejemplo n.º 27
0
 def test_init_param_list(self):
     _list = list([1, 2, 3])
     self.assertEqual(_list, Polynomial(_list).coeffs)
Ejemplo n.º 28
0
 def test_init_fails_on_empty_param(self):
     with self.assertRaises(AttributeError):
         Polynomial([])
Ejemplo n.º 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]))
Ejemplo n.º 30
0
 def test_init_fails_on_incorrect_input_param(self):
     with self.assertRaises(TypeError):
         Polynomial(1)