summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@gmail.com>2008-02-01 06:22:46 (GMT)
committerJeffrey Yasskin <jyasskin@gmail.com>2008-02-01 06:22:46 (GMT)
commitca2b69f765dd8a7f5c8e5c5346572519a8768ec4 (patch)
treee1a5f81f05f96d7f85313182316fdb070cfdf1bc /Lib/test/test_math.py
parent951cc0f474e4757e6954f0435952804211c5637c (diff)
downloadcpython-ca2b69f765dd8a7f5c8e5c5346572519a8768ec4.zip
cpython-ca2b69f765dd8a7f5c8e5c5346572519a8768ec4.tar.gz
cpython-ca2b69f765dd8a7f5c8e5c5346572519a8768ec4.tar.bz2
Move __builtins__.trunc() to math.trunc() per
http://mail.python.org/pipermail/python-dev/2008-January/076626.html and issue 1965.
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index 16f0f4d..e0e72f5 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -237,6 +237,37 @@ class MathTests(unittest.TestCase):
self.ftest('tanh(0)', math.tanh(0), 0)
self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
+ def test_trunc(self):
+ self.assertEqual(math.trunc(1), 1)
+ self.assertEqual(math.trunc(-1), -1)
+ self.assertEqual(type(math.trunc(1)), int)
+ self.assertEqual(type(math.trunc(1.5)), int)
+ self.assertEqual(math.trunc(1.5), 1)
+ self.assertEqual(math.trunc(-1.5), -1)
+ self.assertEqual(math.trunc(1.999999), 1)
+ self.assertEqual(math.trunc(-1.999999), -1)
+ self.assertEqual(math.trunc(-0.999999), -0)
+ self.assertEqual(math.trunc(-100.999), -100)
+
+ class TestTrunc(object):
+ def __trunc__(self):
+ return 23
+
+ class TestNoTrunc(object):
+ pass
+
+ self.assertEqual(math.trunc(TestTrunc()), 23)
+
+ self.assertRaises(TypeError, math.trunc)
+ self.assertRaises(TypeError, math.trunc, 1, 2)
+ # XXX: This is not ideal, but see the comment in math_trunc().
+ self.assertRaises(AttributeError, math.trunc, TestNoTrunc())
+
+ t = TestNoTrunc()
+ t.__trunc__ = lambda *args: args
+ self.assertEquals((), math.trunc(t))
+ self.assertRaises(TypeError, math.trunc, t, 0)
+
def testCopysign(self):
self.assertEqual(math.copysign(1, 42), 1.0)
self.assertEqual(math.copysign(0., 42), 0.0)