def testPolyint(self): p = pypol.poly1d([4, -3, 4, 1]) py.test.raises(ValueError, lambda: funcs.polyint(ONE, -1)) assert funcs.polyint(ONE) == x assert funcs.polyint(TWO) == 2*x assert funcs.polyint(p) == pypol.poly1d([1, -1, 2, 1, 0]) assert funcs.polyint(p, 2) == funcs.polyint(funcs.polyint(p)) \ == pypol.polynomial('+ 1/5x^5 - 1/4x^4 + 2/3x^3 + 1/2x^2')
def testIsSquareDiff(self): assert pypol.polynomial('a6 - 9').is_square_diff() assert pypol.polynomial('a2 - 9').is_square_diff() assert not pypol.polynomial('a').is_square_diff() assert not pypol.polynomial('a2').is_square_diff() assert not pypol.polynomial('a2 - 3').is_square_diff() assert not pypol.polynomial('a2 + 9').is_square_diff() assert not pypol.polynomial('a6 + 9').is_square_diff() assert not pypol.polynomial('a6 - 6').is_square_diff() assert not self.a.is_square_diff()
def testDivmod(self): assert (pypol.polynomial('- x^2 + x'), pypol.polynomial('- 5')) == divmod(self.a, self.c)
def testSub(self): assert pypol.ONE - pypol.x == self.c assert 1 - pypol.x == self.c assert pypol.polynomial('x^3 - a^3 + x + b - 8') == self.a - self.b assert pypol.polynomial('x^3 - 2x^2 + x - 7') == self.a - 2 assert pypol.polynomial('x^3 - 2x^2 + x - 5 - y^2') == self.a - 'y^2'
def testMul(self): assert pypol.polynomial('x^3a - 2x^2a + xa - 5a') == self.a * self.d assert pypol.polynomial('x^3a^3 - 2x^5 - x^3b - 2x^2a^3 + 4x^4 + 2x^2b + xa^3 + x^3 - xb + 3x - 5a^3 + 4x^2 + 5b - 15') == self.a * self.b
def testEvalForm(self): assert '2*y**5*x**3-4*x**2+2' == pypol.polynomial('2x^3y^5 - 4x^2 +2').eval_form
def testAdd(self): assert pypol.polynomial('x^3 + x + a^3 - 4x^2 - b - 2') == self.a + self.b assert pypol.polynomial('x^3 - 2x^2 + x - 6') == self.a + -1 assert pypol.polynomial('x^3 - 2x^2 + x - 5 + y^2') == self.a + 'y^2'
def testPow(self): assert pypol.polynomial('x^2 -2x + 1') == self.c ** 2
def testLcm(self): assert pypol.polynomial('3x^4 - 9x').lcm() in (pypol.polynomial('9x^4'), pypol.polynomial('-9x^4'))
def testGetitem(self): assert (1, {'a': 1}) == pypol.polynomial('a')[0] py.test.raises(IndexError, lambda: pypol.polynomial('a')[2])
def testSetitem(self): self.a[2] = (3, {'x': 3, 'y': 4}) assert pypol.polynomial('x^3 + 3x3y4 - 2x^2 -5') == self.a
def testNeg(self): assert pypol.polynomial('x - 1') == -self.c
def testNonzero(self): p = pypol.polynomial() assert self.a assert not p
def testEq(self): assert pypol.polynomial('x^3 - 2x^2 + x - 5') == self.a
def testUpdate(self): self.d.update('3x - y + 2') assert pypol.polynomial('3x - y + 2') == self.d
def testOrdered(self): assert pypol.polynomial('4a3+6a2+4a+5').isordered() assert pypol.polynomial('4a3+6a2+4a+5').isordered('a') assert not pypol.polynomial('a3+b3+c+ab ').isordered() assert not pypol.polynomial('a3+b3+c+ab ').isordered('a') assert not pypol.polynomial('a3+b3+c+ab ').isordered('b')
def testDiv(self): assert (2 * pypol.x + 1) / 2 == pypol.polynomial('x + 1/2') assert pypol.polynomial('- x^2 + x') == self.a / self.c
def testDelitem(self): del self.a[1:3] assert pypol.polynomial('x^3 - 5') == self.a
def testMod(self): p = pypol.polynomial('x^2 + 3') assert pypol.polynomial('4') == p % self.c
def testDivAll(self): assert pypol.polynomial('2x^3 + 4xy - 16').div_all(-2) == pypol.polynomial('- x^3 - 2xy + 8')
def testGcd(self): assert pypol.polynomial('3x^4 - 9x').gcd() in (pypol.polynomial('3x'), pypol.polynomial('-3x'))
def setup_method(self, method): self.a = pypol.polynomial('x^3 - 2x^2 + x -5') self.b = pypol.polynomial('a^3 - 2x^2 - b + 3') self.c = pypol.polynomial('-x + 1') self.d = pypol.polynomial('a')
def testPolynomial(self): assert type(pypol.polynomial()) == pypol.Polynomial
def testLetters(self): assert ('a', 'b', 'x') == self.b.letters assert () == pypol.polynomial().letters