diff options
author | Guido van Rossum <guido@python.org> | 2007-08-23 22:56:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-23 22:56:55 (GMT) |
commit | 13e05de9efe75f1e645c36ffc4833d2b31d437de (patch) | |
tree | 190fdd972903cbd4074fa77745e598706cea087b /Lib | |
parent | 2fa33db12b8cb6ec1dd1b87df6911e311d98457b (diff) | |
download | cpython-13e05de9efe75f1e645c36ffc4833d2b31d437de.zip cpython-13e05de9efe75f1e645c36ffc4833d2b31d437de.tar.gz cpython-13e05de9efe75f1e645c36ffc4833d2b31d437de.tar.bz2 |
Fix math.ceil() and math.floor() to fall back to __ceil__ and __floor__
methods (respectively). With Keir Mierle.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_math.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index c28902b..2d15f3a 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: + def __ceil__(self): + return 42 + class TestNoCeil: + 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: + def __floor__(self): + return 42 + class TestNoFloor: + 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) |