summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_float.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_float.py')
-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.