test_int_literal.py 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import sys
  2. import unittest
  3. class TestHexOctBin(unittest.TestCase):
  4. def test_hex_baseline(self):
  5. # A few upper/lowercase tests
  6. self.assertEqual(0x0, 0X0)
  7. self.assertEqual(0x1, 0X1)
  8. self.assertEqual(0x123456789abcdef, 0X123456789abcdef)
  9. # Baseline tests
  10. self.assertEqual(0x0, 0)
  11. self.assertEqual(0x10, 16)
  12. self.assertEqual(0x7fffffff, 2147483647)
  13. self.assertEqual(0x7fffffffffffffff, 9223372036854775807)
  14. # Ditto with a minus sign and parentheses
  15. self.assertEqual(-(0x0), 0)
  16. self.assertEqual(-(0x10), -16)
  17. self.assertEqual(-(0x7fffffff), -2147483647)
  18. self.assertEqual(-(0x7fffffffffffffff), -9223372036854775807)
  19. # Ditto with a minus sign and NO parentheses
  20. self.assertEqual(-0x0, 0)
  21. self.assertEqual(-0x10, -16)
  22. self.assertEqual(-0x7fffffff, -2147483647)
  23. self.assertEqual(-0x7fffffffffffffff, -9223372036854775807)
  24. def test_hex_unsigned(self):
  25. # Positive constants
  26. self.assertEqual(0x80000000, 2147483648)
  27. self.assertEqual(0xffffffff, 4294967295)
  28. # Ditto with a minus sign and parentheses
  29. self.assertEqual(-(0x80000000), -2147483648)
  30. self.assertEqual(-(0xffffffff), -4294967295)
  31. # Ditto with a minus sign and NO parentheses
  32. # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  33. self.assertEqual(-0x80000000, -2147483648)
  34. self.assertEqual(-0xffffffff, -4294967295)
  35. # Positive constants
  36. self.assertEqual(0x8000000000000000, 9223372036854775808)
  37. self.assertEqual(0xffffffffffffffff, 18446744073709551615)
  38. # Ditto with a minus sign and parentheses
  39. self.assertEqual(-(0x8000000000000000), -9223372036854775808)
  40. self.assertEqual(-(0xffffffffffffffff), -18446744073709551615)
  41. # Ditto with a minus sign and NO parentheses
  42. # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  43. self.assertEqual(-0x8000000000000000, -9223372036854775808)
  44. self.assertEqual(-0xffffffffffffffff, -18446744073709551615)
  45. def test_oct_baseline(self):
  46. # A few upper/lowercase tests
  47. self.assertEqual(0o0, 0O0)
  48. self.assertEqual(0o1, 0O1)
  49. self.assertEqual(0o1234567, 0O1234567)
  50. # Baseline tests
  51. self.assertEqual(0o0, 0)
  52. self.assertEqual(0o20, 16)
  53. self.assertEqual(0o17777777777, 2147483647)
  54. self.assertEqual(0o777777777777777777777, 9223372036854775807)
  55. # Ditto with a minus sign and parentheses
  56. self.assertEqual(-(0o0), 0)
  57. self.assertEqual(-(0o20), -16)
  58. self.assertEqual(-(0o17777777777), -2147483647)
  59. self.assertEqual(-(0o777777777777777777777), -9223372036854775807)
  60. # Ditto with a minus sign and NO parentheses
  61. self.assertEqual(-0o0, 0)
  62. self.assertEqual(-0o20, -16)
  63. self.assertEqual(-0o17777777777, -2147483647)
  64. self.assertEqual(-0o777777777777777777777, -9223372036854775807)
  65. def test_oct_unsigned(self):
  66. # Positive constants
  67. self.assertEqual(0o20000000000, 2147483648)
  68. self.assertEqual(0o37777777777, 4294967295)
  69. # Ditto with a minus sign and parentheses
  70. self.assertEqual(-(0o20000000000), -2147483648)
  71. self.assertEqual(-(0o37777777777), -4294967295)
  72. # Ditto with a minus sign and NO parentheses
  73. # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  74. self.assertEqual(-0o20000000000, -2147483648)
  75. self.assertEqual(-0o37777777777, -4294967295)
  76. # Positive constants
  77. self.assertEqual(0o1000000000000000000000, 9223372036854775808)
  78. self.assertEqual(0o1777777777777777777777, 18446744073709551615)
  79. # Ditto with a minus sign and parentheses
  80. self.assertEqual(-(0o1000000000000000000000), -9223372036854775808)
  81. self.assertEqual(-(0o1777777777777777777777), -18446744073709551615)
  82. # Ditto with a minus sign and NO parentheses
  83. # This failed in Python 2.2 through 2.2.2 and in 2.3a1
  84. self.assertEqual(-0o1000000000000000000000, -9223372036854775808)
  85. self.assertEqual(-0o1777777777777777777777, -18446744073709551615)
  86. """
  87. we do not support binary literals
  88. """
  89. if __name__ == '__main__':
  90. unittest.main()