diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-12 21:19:51 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-12 21:19:51 (GMT) |
commit | 48e47aaa28d6dfdae128142ffcbc4b0642422e90 (patch) | |
tree | f62918798a55edb3aa09e9c95ec92d965fc5283e /Lib/test/test_fractions.py | |
parent | f0eeedf0d8ffff9d7ea8874e60992845595f091f (diff) | |
download | cpython-48e47aaa28d6dfdae128142ffcbc4b0642422e90.zip cpython-48e47aaa28d6dfdae128142ffcbc4b0642422e90.tar.gz cpython-48e47aaa28d6dfdae128142ffcbc4b0642422e90.tar.bz2 |
Issue #22486: Added the math.gcd() function. The fractions.gcd() function now is
deprecated. Based on patch by Mark Dickinson.
Diffstat (limited to 'Lib/test/test_fractions.py')
-rw-r--r-- | Lib/test/test_fractions.py | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index 2dd528f..1699852 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -8,6 +8,7 @@ import operator import fractions import sys import unittest +import warnings from copy import copy, deepcopy from pickle import dumps, loads F = fractions.Fraction @@ -49,7 +50,7 @@ class DummyRational(object): """Test comparison of Fraction with a naive rational implementation.""" def __init__(self, num, den): - g = gcd(num, den) + g = math.gcd(num, den) self.num = num // g self.den = den // g @@ -83,16 +84,26 @@ class DummyFraction(fractions.Fraction): class GcdTest(unittest.TestCase): def testMisc(self): - self.assertEqual(0, gcd(0, 0)) - self.assertEqual(1, gcd(1, 0)) - self.assertEqual(-1, gcd(-1, 0)) - self.assertEqual(1, gcd(0, 1)) - self.assertEqual(-1, gcd(0, -1)) - self.assertEqual(1, gcd(7, 1)) - self.assertEqual(-1, gcd(7, -1)) - self.assertEqual(1, gcd(-23, 15)) - self.assertEqual(12, gcd(120, 84)) - self.assertEqual(-12, gcd(84, -120)) + # fractions.gcd() is deprecated + with self.assertWarnsRegex(DeprecationWarning, r'fractions\.gcd'): + gcd(1, 1) + with warnings.catch_warnings(): + warnings.filterwarnings('ignore', r'fractions\.gcd', + DeprecationWarning) + self.assertEqual(0, gcd(0, 0)) + self.assertEqual(1, gcd(1, 0)) + self.assertEqual(-1, gcd(-1, 0)) + self.assertEqual(1, gcd(0, 1)) + self.assertEqual(-1, gcd(0, -1)) + self.assertEqual(1, gcd(7, 1)) + self.assertEqual(-1, gcd(7, -1)) + self.assertEqual(1, gcd(-23, 15)) + self.assertEqual(12, gcd(120, 84)) + self.assertEqual(-12, gcd(84, -120)) + self.assertEqual(gcd(120.0, 84), 12.0) + self.assertEqual(gcd(120, 84.0), 12.0) + self.assertEqual(gcd(F(120), F(84)), F(12)) + self.assertEqual(gcd(F(120, 77), F(84, 55)), F(12, 385)) def _components(r): |