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