Exemplo n.º 1
0
 def testCubic(self):
     self.compareRoots(mathutils.realpolyroots(0, 0, 0, 1), [])
     self.compareRoots(mathutils.realpolyroots(0, 0, 1, 1), [-1])
     self.compareRoots(mathutils.realpolyroots(0, 1, -4, 3), [1, 3])
     self.compareRoots(mathutils.realpolyroots(1, -9, 23, -15), [1, 3, 5])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, 2.3, 4.2)), [1.7, 2.3, 4.2])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, -2.3, 4.2)), [-2.3, 1.7, 4.2])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, -2.3, -4.2)), [-4.2, -2.3, 1.7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7), 2.3, 1)), [1.7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7), 2.3, -1)), [1.3, 1.7, 3.3])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7), 2.3, -4)), [0.3, 1.7, 4.3])
Exemplo n.º 2
0
 def testQuadratic(self):
     self.compareRoots(mathutils.realpolyroots(0, 1, 1), [-1])
     self.compareRoots(mathutils.realpolyroots(1, -4, 3), [1, 3])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, 2.3)), [1.7, 2.3])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(2.3, 1.7)), [1.7, 2.3])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, -2.3)), [-2.3, 1.7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(-2.3, 1.7)), [-2.3, 1.7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, 1.7)), [1.7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots([1], 1.7, 1)), [])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots([1], 1.7, -1)), [0.7, 2.7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots([1], 1.7, -4)), [-0.3, 3.7])
Exemplo n.º 3
0
 def testLinear(self):
     self.compareRoots(mathutils.realpolyroots(0, 1), [])
     self.compareRoots(mathutils.realpolyroots(0, 0), [0])
     self.compareRoots(mathutils.realpolyroots(1, 1), [-1])
     self.compareRoots(mathutils.realpolyroots(2, 0), [0])
     self.compareRoots(mathutils.realpolyroots(4, -1), [0.25])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7)), [1.7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(-42)), [-42])
Exemplo n.º 4
0
 def testQuartic(self):
     self.compareRoots(mathutils.realpolyroots(0, 0, 0, 0, 1), [])
     self.compareRoots(mathutils.realpolyroots(0, 0, 0, 1, 1), [-1])
     self.compareRoots(mathutils.realpolyroots(0, 1, -9, 23, -15), [1, 3, 5])
     self.compareRoots(mathutils.realpolyroots(1, -16, 86, -176, 105), [1, 3, 5, 7])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, 2.3, 4.2, 13)), [1.7, 2.3, 4.2, 13])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, -2.3, 4.2, 13)), [-2.3, 1.7, 4.2, 13])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyRoots(1.7, -2.3, -4.2, 13)), [-4.2, -2.3, 1.7, 13])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7, 2.3), 4.2, 1)), [1.7, 2.3])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7, 2.3), 4.2, -1)), [1.7, 2.3, 3.2, 5.2])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7, 2.3), 4.2, -4)), [1.7, 2.2, 2.3, 6.2])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7, -2.3), 4.2, -1)), [-2.3, 1.7, 3.2, 5.2])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyRoots(1.7, -2.3), 4.2, -4)), [-2.3, 1.7, 2.2, 6.2])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyNonroots([1], 1.7, 1), 2.3, 1)), [])
     self.compareRoots(mathutils.realpolyroots(*self.makePolyNonroots(self.makePolyNonroots([1], 1.7, 1), 2.3, -1)), [1.3, 3.3])
Exemplo n.º 5
0
 def testConstant(self):
     self.compareRoots(mathutils.realpolyroots(1), [])
     self.compareRoots(mathutils.realpolyroots(0), [0])