mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-101291: Add low level, unstable API for pylong (GH-101685)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
ab71acd67b
commit
93923793f6
8 changed files with 139 additions and 20 deletions
39
Lib/test/test_capi/test_long.py
Normal file
39
Lib/test/test_capi/test_long.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import unittest
|
||||
import sys
|
||||
|
||||
from test.support import import_helper
|
||||
|
||||
# Skip this test if the _testcapi module isn't available.
|
||||
_testcapi = import_helper.import_module('_testcapi')
|
||||
|
||||
|
||||
class LongTests(unittest.TestCase):
|
||||
|
||||
def test_compact(self):
|
||||
for n in {
|
||||
# Edge cases
|
||||
*(2**n for n in range(66)),
|
||||
*(-2**n for n in range(66)),
|
||||
*(2**n - 1 for n in range(66)),
|
||||
*(-2**n + 1 for n in range(66)),
|
||||
# Essentially random
|
||||
*(37**n for n in range(14)),
|
||||
*(-37**n for n in range(14)),
|
||||
}:
|
||||
with self.subTest(n=n):
|
||||
is_compact, value = _testcapi.call_long_compact_api(n)
|
||||
if is_compact:
|
||||
self.assertEqual(n, value)
|
||||
|
||||
def test_compact_known(self):
|
||||
# Sanity-check some implementation details (we don't guarantee
|
||||
# that these are/aren't compact)
|
||||
self.assertEqual(_testcapi.call_long_compact_api(-1), (True, -1))
|
||||
self.assertEqual(_testcapi.call_long_compact_api(0), (True, 0))
|
||||
self.assertEqual(_testcapi.call_long_compact_api(256), (True, 256))
|
||||
self.assertEqual(_testcapi.call_long_compact_api(sys.maxsize),
|
||||
(False, -1))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue