Skip to content

Commit cc07ee5

Browse files
bpo-26680: Adds tests for Fraction.is_integer called as an instance method.
The tests for the Rational abstract base class use an unbound method to sidestep the inability to directly instantiate Rational. These tests check that everything works correct as an instance method.
1 parent 6a905a8 commit cc07ee5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Lib/test/test_fractions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,17 @@ def denominator(self):
724724
self.assertEqual(type(f.numerator), myint)
725725
self.assertEqual(type(f.denominator), myint)
726726

727+
def test_is_integer(self):
728+
# Issue #26680: Incorporating number.is_integer into Fraction
729+
self.assertTrue(F(-1, 1).is_integer())
730+
self.assertTrue(F(0, 1).is_integer())
731+
self.assertTrue(F(1, 1).is_integer())
732+
self.assertTrue(F(42, 1).is_integer())
733+
self.assertTrue(F(2, 2).is_integer())
734+
self.assertTrue(F(8, 4).is_integer())
735+
self.assertFalse(F(1, 2).is_integer())
736+
self.assertFalse(F(1, 3).is_integer())
737+
self.assertFalse(F(2, 3).is_integer())
727738

728739
if __name__ == '__main__':
729740
unittest.main()

0 commit comments

Comments
 (0)