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