summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>2019-12-15 22:00:28 (GMT)
committerVictor Stinner <vstinner@python.org>2019-12-15 22:00:28 (GMT)
commitcb8b946ac10386e6cab1376945f64f683b5b16d3 (patch)
treede739cc3abe542c43b563cb6167f28757bdcb536 /Lib
parentb08d3f71beab59653edfbbcf7b92a7bc8050d6b8 (diff)
downloadcpython-cb8b946ac10386e6cab1376945f64f683b5b16d3.zip
cpython-cb8b946ac10386e6cab1376945f64f683b5b16d3.tar.gz
cpython-cb8b946ac10386e6cab1376945f64f683b5b16d3.tar.bz2
bpo-38629: implement __floor__ and __ceil__ for float type (GH-16985)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_float.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index b656582..9651281 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -312,6 +312,34 @@ class GeneralFloatCases(unittest.TestCase):
# distinguishes -0.0 and 0.0.
self.assertEqual((a, copysign(1.0, a)), (b, copysign(1.0, b)))
+ def test_float_floor(self):
+ self.assertIsInstance(float(0.5).__floor__(), int)
+ self.assertEqual(float(0.5).__floor__(), 0)
+ self.assertEqual(float(1.0).__floor__(), 1)
+ self.assertEqual(float(1.5).__floor__(), 1)
+ self.assertEqual(float(-0.5).__floor__(), -1)
+ self.assertEqual(float(-1.0).__floor__(), -1)
+ self.assertEqual(float(-1.5).__floor__(), -2)
+ self.assertEqual(float(1.23e167).__floor__(), 1.23e167)
+ self.assertEqual(float(-1.23e167).__floor__(), -1.23e167)
+ self.assertRaises(ValueError, float("nan").__floor__)
+ self.assertRaises(OverflowError, float("inf").__floor__)
+ self.assertRaises(OverflowError, float("-inf").__floor__)
+
+ def test_float_ceil(self):
+ self.assertIsInstance(float(0.5).__ceil__(), int)
+ self.assertEqual(float(0.5).__ceil__(), 1)
+ self.assertEqual(float(1.0).__ceil__(), 1)
+ self.assertEqual(float(1.5).__ceil__(), 2)
+ self.assertEqual(float(-0.5).__ceil__(), 0)
+ self.assertEqual(float(-1.0).__ceil__(), -1)
+ self.assertEqual(float(-1.5).__ceil__(), -1)
+ self.assertEqual(float(1.23e167).__ceil__(), 1.23e167)
+ self.assertEqual(float(-1.23e167).__ceil__(), -1.23e167)
+ self.assertRaises(ValueError, float("nan").__ceil__)
+ self.assertRaises(OverflowError, float("inf").__ceil__)
+ self.assertRaises(OverflowError, float("-inf").__ceil__)
+
@support.requires_IEEE_754
def test_float_mod(self):
# Check behaviour of % operator for IEEE 754 special cases.