Skip to content

Commit

Permalink
add pylong_import() tests on normalize + singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jul 4, 2024
1 parent b67b73a commit 294f53a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Lib/test/test_capi/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,13 @@ def test_long_import(self):
self.assertEqual(pylong_import(0, [1, 2, 3]),
shift**2 * 3 + shift * 2 + 1)

# normalize
self.assertEqual(pylong_import(0, [123, 0, 0]), 123)

# test singletons + normalize
for num in (-2, 0, 1, 5, 42, 100):
self.assertIs(pylong_import(bool(num < 0), [abs(num), 0]), num)

# round trip: Python int -> export -> Python int
pylong_export = _testcapi.pylong_export
numbers = [*range(0, 10), 12345, 0xdeadbeef, 2**100, 2**100-1]
Expand Down

0 comments on commit 294f53a

Please sign in to comment.