예제 #1
0
	def test(self):
		self.assertFalse(Zero)
		self.assertFalse(Polynomial([0,0]))
		self.assertEqual(Zero.degree(), 0)
		self.assertEqual(One.degree(), 0)
		self.assertFalse(One.zeros(), "Constants have no zero")
		self.assertEqual(One, Polynomial([1,0,0,0]))
		self.assertEqual(One, Polynomial(1), "Creation from scalars")

		self.assertEqual(X.degree(), 1)
		self.assertEqual((X+X).degree(), 1)
		self.assertEqual(One.degree(), 0)
		self.assertEqual(X.degree(), 1)

		r = np.random.random()
		self.assertEqual(Zero(r), 0)
		self.assertEqual(One(r), 1)
		self.assertEqual(X(r), r)

		self.assertEqual(Zero, 0)
		self.assertEqual(One, 1)

		self.assertFalse(Zero)
		self.assertTrue(One)

		self.assertFalse(2*Zero != 3*Zero)

		self.assertEqual(X.differentiate(), 1)
		self.assertEqual((X**2).differentiate(), 2*X)
		self.assertEqual((X-1)*(X+1), X**2 - 1)

		self.assertNotEqual(Polynomial((0,)), Polynomial([0,2]))
예제 #2
0
	def test_Zero_zeros(self):
		"""Asking for zeros of Zero raises an exception"""
		with self.assertRaises(Polynomial.ConstantPolynomialError):
			Zero.zeros()