mirror of
https://github.com/python/cpython.git
synced 2025-08-14 13:59:20 +00:00
bpo-37819: Add Fraction.as_integer_ratio() (GH-15212) (GH-15215)
(cherry picked from commit f03b4c8a48
)
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
parent
9500bbe937
commit
5ba1cb0393
4 changed files with 23 additions and 0 deletions
|
@ -302,6 +302,12 @@ class FractionTest(unittest.TestCase):
|
|||
ValueError, "cannot convert NaN to integer ratio",
|
||||
F.from_decimal, Decimal("snan"))
|
||||
|
||||
def test_as_integer_ratio(self):
|
||||
self.assertEqual(F(4, 6).as_integer_ratio(), (2, 3))
|
||||
self.assertEqual(F(-4, 6).as_integer_ratio(), (-2, 3))
|
||||
self.assertEqual(F(4, -6).as_integer_ratio(), (-2, 3))
|
||||
self.assertEqual(F(0, 6).as_integer_ratio(), (0, 1))
|
||||
|
||||
def testLimitDenominator(self):
|
||||
rpi = F('3.1415926535897932')
|
||||
self.assertEqual(rpi.limit_denominator(10000), F(355, 113))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue