summaryrefslogtreecommitdiff
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-01-03 02:21:52 +0000
committerJeffrey Yasskin <jyasskin@gmail.com>2008-01-03 02:21:52 +0000
commit2f3c16be73a8562d357b9b13bbb8088e275840a7 (patch)
tree5334d4bd6c8b6456da10c0be232fb8bf95b1aca7 /Lib/test/test_math.py
parent27edd829d7673a642cf5b37c3011454ec33cb715 (diff)
downloadcpython-git-2f3c16be73a8562d357b9b13bbb8088e275840a7.tar.gz
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689.
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index d86298d01b..98e4623c29 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -58,6 +58,19 @@ class MathTests(unittest.TestCase):
self.ftest('ceil(-1.0)', math.ceil(-1.0), -1)
self.ftest('ceil(-1.5)', math.ceil(-1.5), -1)
+ class TestCeil(object):
+ def __ceil__(self):
+ return 42
+ class TestNoCeil(object):
+ pass
+ self.ftest('ceil(TestCeil())', math.ceil(TestCeil()), 42)
+ self.assertRaises(TypeError, math.ceil, TestNoCeil())
+
+ t = TestNoCeil()
+ t.__ceil__ = lambda *args: args
+ self.assertRaises(TypeError, math.ceil, t)
+ self.assertRaises(TypeError, math.ceil, t, 0)
+
def testCos(self):
self.assertRaises(TypeError, math.cos)
self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0)
@@ -101,6 +114,19 @@ class MathTests(unittest.TestCase):
self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167)
self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167)
+ class TestFloor(object):
+ def __floor__(self):
+ return 42
+ class TestNoFloor(object):
+ pass
+ self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42)
+ self.assertRaises(TypeError, math.floor, TestNoFloor())
+
+ t = TestNoFloor()
+ t.__floor__ = lambda *args: args
+ self.assertRaises(TypeError, math.floor, t)
+ self.assertRaises(TypeError, math.floor, t, 0)
+
def testFmod(self):
self.assertRaises(TypeError, math.fmod)
self.ftest('fmod(10,1)', math.fmod(10,1), 0)