1  import unittest
       2  import sys
       3  
       4  from test.support import import_helper
       5  
       6  # Skip this test if the _testcapi module isn't available.
       7  _testcapi = import_helper.import_module('_testcapi')
       8  
       9  
      10  class ESC[4;38;5;81mLongTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
      11  
      12      def test_compact(self):
      13          for n in {
      14              # Edge cases
      15              *(2**n for n in range(66)),
      16              *(-2**n for n in range(66)),
      17              *(2**n - 1 for n in range(66)),
      18              *(-2**n + 1 for n in range(66)),
      19              # Essentially random
      20              *(37**n for n in range(14)),
      21              *(-37**n for n in range(14)),
      22          }:
      23              with self.subTest(n=n):
      24                  is_compact, value = _testcapi.call_long_compact_api(n)
      25                  if is_compact:
      26                      self.assertEqual(n, value)
      27  
      28      def test_compact_known(self):
      29          # Sanity-check some implementation details (we don't guarantee
      30          # that these are/aren't compact)
      31          self.assertEqual(_testcapi.call_long_compact_api(-1), (True, -1))
      32          self.assertEqual(_testcapi.call_long_compact_api(0), (True, 0))
      33          self.assertEqual(_testcapi.call_long_compact_api(256), (True, 256))
      34          self.assertEqual(_testcapi.call_long_compact_api(sys.maxsize),
      35                           (False, -1))
      36  
      37  
      38  if __name__ == "__main__":
      39      unittest.main()