summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_numeric_tower.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_numeric_tower.py')
-rw-r--r--Lib/test/test_numeric_tower.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_numeric_tower.py b/Lib/test/test_numeric_tower.py
index c54dedb..4e46aac 100644
--- a/Lib/test/test_numeric_tower.py
+++ b/Lib/test/test_numeric_tower.py
@@ -6,6 +6,7 @@ import math
import sys
import operator
+from numbers import Real, Rational, Integral
from decimal import Decimal as D
from fractions import Fraction as F
@@ -198,5 +199,35 @@ class ComparisonTest(unittest.TestCase):
self.assertRaises(TypeError, op, v, z)
+class IsIntegerTest(unittest.TestCase):
+
+ def test_real_is_integer(self):
+ self.assertTrue(Real.is_integer(-1.0))
+ self.assertTrue(Real.is_integer(0.0))
+ self.assertTrue(Real.is_integer(1.0))
+ self.assertTrue(Real.is_integer(42.0))
+
+ self.assertFalse(Real.is_integer(-0.5))
+ self.assertFalse(Real.is_integer(4.2))
+
+ def test_rational_is_integer(self):
+ self.assertTrue(Rational.is_integer(F(-1, 1)))
+ self.assertTrue(Rational.is_integer(F(0, 1)))
+ self.assertTrue(Rational.is_integer(F(1, 1)))
+ self.assertTrue(Rational.is_integer(F(42, 1)))
+ self.assertTrue(Rational.is_integer(F(2, 2)))
+ self.assertTrue(Rational.is_integer(F(8, 4)))
+
+ self.assertFalse(Rational.is_integer(F(1, 2)))
+ self.assertFalse(Rational.is_integer(F(1, 3)))
+ self.assertFalse(Rational.is_integer(F(2, 3)))
+
+ def test_integral_is_integer(self):
+ self.assertTrue(Integral.is_integer(-1))
+ self.assertTrue(Integral.is_integer(0))
+ self.assertTrue(Integral.is_integer(1))
+ self.assertTrue(Integral.is_integer(1729))
+
+
if __name__ == '__main__':
unittest.main()