summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-01 08:12:03 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-01 08:12:03 (GMT)
commit400adb030a78c3fcb1eb458b25c990449fbf3c93 (patch)
tree8dc99c561ec91ec9d2f887eb7b04e7227d30b8ac /Lib/test/test_math.py
parenta7712090f78d19d0711553d58e403c9fa44474a8 (diff)
downloadcpython-400adb030a78c3fcb1eb458b25c990449fbf3c93.zip
cpython-400adb030a78c3fcb1eb458b25c990449fbf3c93.tar.gz
cpython-400adb030a78c3fcb1eb458b25c990449fbf3c93.tar.bz2
Merged revisions 60475-60479,60481-60488 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60482 | raymond.hettinger | 2008-01-31 23:07:16 +0100 (Thu, 31 Jan 2008) | 1 line Minor wordsmithing on docstring ........ r60483 | mark.dickinson | 2008-01-31 23:17:37 +0100 (Thu, 31 Jan 2008) | 5 lines Issue #1678380. Fix a bug that identifies 0j and -0j when they appear in the same code unit. The fix is essentially the same as the fix for a previous bug identifying 0. and -0. ........ r60484 | christian.heimes | 2008-02-01 00:08:23 +0100 (Fri, 01 Feb 2008) | 1 line Fixed bug #1983: Return from fork() is pid_t, not int ........ r60486 | jeffrey.yasskin | 2008-02-01 07:22:46 +0100 (Fri, 01 Feb 2008) | 4 lines Move __builtins__.trunc() to math.trunc() per http://mail.python.org/pipermail/python-dev/2008-January/076626.html and issue 1965. ........ r60487 | jeffrey.yasskin | 2008-02-01 08:05:46 +0100 (Fri, 01 Feb 2008) | 3 lines Roll back r60248. It's useful to encourage users not to change Rational instances. ........ r60488 | neal.norwitz | 2008-02-01 08:22:59 +0100 (Fri, 01 Feb 2008) | 1 line Fix refleak ........
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index 2333392..aa44253 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -233,6 +233,38 @@ 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)
+ self.assertRaises(TypeError, math.trunc, TestNoTrunc())
+
+ # XXX Doesn't work because the method is looked up on
+ # the type only.
+ #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)