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