summaryrefslogtreecommitdiffstats
path: root/Lib/test/datetimetester.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2015-02-28 15:44:47 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2015-02-28 15:44:47 (GMT)
commit184291aeb74249e644b3df581d240811e4b8a6e2 (patch)
tree2a75bb0cc749c5e0dace84b712f1604d1256daf9 /Lib/test/datetimetester.py
parent6ab0ec935260247640fd963f29e446238fb436bd (diff)
parent24d3deefcf2f78b12fc29ed4c9a3811d46c534bb (diff)
downloadcpython-184291aeb74249e644b3df581d240811e4b8a6e2.zip
cpython-184291aeb74249e644b3df581d240811e4b8a6e2.tar.gz
cpython-184291aeb74249e644b3df581d240811e4b8a6e2.tar.bz2
Fixes #23521: Corrected pure python implementation of timedelta division.
* Eliminated OverflowError from timedelta * float for some floats; * Corrected rounding in timedlta true division.
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r--Lib/test/datetimetester.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 7935cf2..40ef1ba 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -62,6 +62,33 @@ class TestModule(unittest.TestCase):
'tzinfo'])
self.assertEqual(names - allowed, set([]))
+ def test_divide_and_round(self):
+ if '_Fast' in str(self):
+ return
+ dar = datetime_module._divide_and_round
+
+ self.assertEqual(dar(-10, -3), 3)
+ self.assertEqual(dar(5, -2), -2)
+
+ # four cases: (2 signs of a) x (2 signs of b)
+ self.assertEqual(dar(7, 3), 2)
+ self.assertEqual(dar(-7, 3), -2)
+ self.assertEqual(dar(7, -3), -2)
+ self.assertEqual(dar(-7, -3), 2)
+
+ # ties to even - eight cases:
+ # (2 signs of a) x (2 signs of b) x (even / odd quotient)
+ self.assertEqual(dar(10, 4), 2)
+ self.assertEqual(dar(-10, 4), -2)
+ self.assertEqual(dar(10, -4), -2)
+ self.assertEqual(dar(-10, -4), 2)
+
+ self.assertEqual(dar(6, 4), 2)
+ self.assertEqual(dar(-6, 4), -2)
+ self.assertEqual(dar(6, -4), -2)
+ self.assertEqual(dar(-6, -4), 2)
+
+
#############################################################################
# tzinfo tests
@@ -394,6 +421,10 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
eq((-3*us) * 0.5, -2*us)
eq((-5*us) * 0.5, -2*us)
+ # Issue #23521
+ eq(td(seconds=1) * 0.123456, td(microseconds=123456))
+ eq(td(seconds=1) * 0.6112295, td(microseconds=611229))
+
# Division by int and float
eq((3*us) / 2, 2*us)
eq((5*us) / 2, 2*us)
@@ -408,6 +439,9 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
for i in range(-10, 10):
eq((i*us/-3)//us, round(i/-3))
+ # Issue #23521
+ eq(td(seconds=1) / (1 / 0.6112295), td(microseconds=611229))
+
# Issue #11576
eq(td(999999999, 86399, 999999) - td(999999999, 86399, 999998),
td(0, 0, 1))