diff options
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r-- | Lib/test/test_math.py | 32 |
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) |