Example #1
0
 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')
Example #2
0
 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()
Example #3
0
 def testDivmod(self):
     assert (pypol.polynomial('- x^2 + x'), pypol.polynomial('- 5')) == divmod(self.a, self.c)
Example #4
0
 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'
Example #5
0
 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
Example #6
0
 def testEvalForm(self):
     assert '2*y**5*x**3-4*x**2+2' == pypol.polynomial('2x^3y^5 - 4x^2 +2').eval_form
Example #7
0
 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'
Example #8
0
 def testPow(self):
     assert pypol.polynomial('x^2 -2x + 1') == self.c ** 2
Example #9
0
 def testLcm(self):
     assert pypol.polynomial('3x^4 - 9x').lcm() in (pypol.polynomial('9x^4'), pypol.polynomial('-9x^4'))
Example #10
0
 def testGetitem(self):
     assert (1, {'a': 1}) == pypol.polynomial('a')[0]
     py.test.raises(IndexError, lambda: pypol.polynomial('a')[2])
Example #11
0
 def testSetitem(self):
     self.a[2] = (3, {'x': 3, 'y': 4})
     assert pypol.polynomial('x^3 + 3x3y4 - 2x^2 -5') == self.a
Example #12
0
 def testNeg(self):
     assert pypol.polynomial('x - 1') == -self.c
Example #13
0
 def testNonzero(self):
     p = pypol.polynomial()
     assert self.a
     assert not p
Example #14
0
 def testEq(self):
     assert pypol.polynomial('x^3 - 2x^2 + x - 5') == self.a
Example #15
0
 def testUpdate(self):
     self.d.update('3x - y + 2')
     assert pypol.polynomial('3x - y + 2') == self.d
Example #16
0
 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')
Example #17
0
 def testDiv(self):
     assert (2 * pypol.x + 1) / 2 == pypol.polynomial('x + 1/2')
     assert pypol.polynomial('- x^2 + x') == self.a / self.c
Example #18
0
 def testDelitem(self):
     del self.a[1:3]
     assert pypol.polynomial('x^3 - 5') == self.a
Example #19
0
 def testMod(self):
     p = pypol.polynomial('x^2 + 3')
     assert pypol.polynomial('4') == p % self.c
Example #20
0
 def testDivAll(self):
     assert pypol.polynomial('2x^3 + 4xy - 16').div_all(-2) == pypol.polynomial('- x^3 - 2xy + 8')
Example #21
0
 def testGcd(self):
     assert pypol.polynomial('3x^4 - 9x').gcd() in (pypol.polynomial('3x'), pypol.polynomial('-3x'))
Example #22
0
 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')
Example #23
0
 def testPolynomial(self):
     assert type(pypol.polynomial()) == pypol.Polynomial
Example #24
0
 def testLetters(self):
     assert ('a', 'b', 'x') == self.b.letters
     assert () == pypol.polynomial().letters