diff options
author | ananthan-123 <ananthakrishnan15.2001@gmail.com> | 2020-02-19 18:21:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 18:21:37 (GMT) |
commit | f2ee21d858bc03dd801b97afe60ee2ea289e2fe9 (patch) | |
tree | 7a35d8b02a53df4505d275b67bc56462cda33619 /Lib | |
parent | 4dee92b0ad9f4e3ea2fbbbb5253340801bb92dc7 (diff) | |
download | cpython-f2ee21d858bc03dd801b97afe60ee2ea289e2fe9.zip cpython-f2ee21d858bc03dd801b97afe60ee2ea289e2fe9.tar.gz cpython-f2ee21d858bc03dd801b97afe60ee2ea289e2fe9.tar.bz2 |
bpo-39479:Add math.lcm() function: Least Common Multiple (#18547)
* Update math.rst
* Update math.rst
* updated whats new
* Update test_math.py
* Update mathmodule.c
* Update mathmodule.c.h
* Update ACKS
* 📜🤖 Added by blurb_it.
* Update 3.9.rst
* Update 2020-02-18-12-37-16.bpo-39479.j3UcCq.rst
* Update math.rst
* Update 2020-02-18-12-37-16.bpo-39479.j3UcCq.rst
* Update test_math.py
* Update ACKS
* Update mathmodule.c.h
* Update mathmodule.c
* Update mathmodule.c.h
* Update mathmodule.c.h
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_math.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index b3301f6..ad8273d 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -974,6 +974,41 @@ class MathTests(unittest.TestCase): with self.assertRaises(TypeError): math.isqrt(value) + def test_lcm(self): + lcm = math.lcm + self.assertEqual(lcm(0, 0), 0) + self.assertEqual(lcm(1, 0), 0) + self.assertEqual(lcm(-1, 0), 0) + self.assertEqual(lcm(0, 1), 0) + self.assertEqual(lcm(0, -1), 0) + self.assertEqual(lcm(7, 1), 7) + self.assertEqual(lcm(7, -1), 7) + self.assertEqual(lcm(-23, 15), 345) + self.assertEqual(lcm(120, 84), 840) + self.assertEqual(lcm(84, -120), 840) + self.assertEqual(lcm(1216342683557601535506311712, + 436522681849110124616458784), + 16592536571065866494401400422922201534178938447014944) + x = 43461045657039990237 + y = 10645022458251153277 + + for c in (652560, + 57655923087165495981): + a = x * c + b = y * c + d = x * y * c + self.assertEqual(lcm(a, b), d) + self.assertEqual(lcm(b, a), d) + self.assertEqual(lcm(-a, b), d) + self.assertEqual(lcm(b, -a), d) + self.assertEqual(lcm(a, -b), d) + self.assertEqual(lcm(-b, a), d) + self.assertEqual(lcm(-a, -b), d) + self.assertEqual(lcm(-b, -a), d) + self.assertEqual(lcm(MyIndexable(120), MyIndexable(84)), 840) + self.assertRaises(TypeError, lcm, 120.0, 84) + self.assertRaises(TypeError, lcm, 120, 84.0) + def testLdexp(self): self.assertRaises(TypeError, math.ldexp) self.ftest('ldexp(0,1)', math.ldexp(0,1), 0) |