1 | n/a | """Test correct treatment of hex/oct constants. |
---|
2 | n/a | |
---|
3 | n/a | This is complex because of changes due to PEP 237. |
---|
4 | n/a | """ |
---|
5 | n/a | |
---|
6 | n/a | import unittest |
---|
7 | n/a | |
---|
8 | n/a | class TestHexOctBin(unittest.TestCase): |
---|
9 | n/a | |
---|
10 | n/a | def test_hex_baseline(self): |
---|
11 | n/a | # A few upper/lowercase tests |
---|
12 | n/a | self.assertEqual(0x0, 0X0) |
---|
13 | n/a | self.assertEqual(0x1, 0X1) |
---|
14 | n/a | self.assertEqual(0x123456789abcdef, 0X123456789abcdef) |
---|
15 | n/a | # Baseline tests |
---|
16 | n/a | self.assertEqual(0x0, 0) |
---|
17 | n/a | self.assertEqual(0x10, 16) |
---|
18 | n/a | self.assertEqual(0x7fffffff, 2147483647) |
---|
19 | n/a | self.assertEqual(0x7fffffffffffffff, 9223372036854775807) |
---|
20 | n/a | # Ditto with a minus sign and parentheses |
---|
21 | n/a | self.assertEqual(-(0x0), 0) |
---|
22 | n/a | self.assertEqual(-(0x10), -16) |
---|
23 | n/a | self.assertEqual(-(0x7fffffff), -2147483647) |
---|
24 | n/a | self.assertEqual(-(0x7fffffffffffffff), -9223372036854775807) |
---|
25 | n/a | # Ditto with a minus sign and NO parentheses |
---|
26 | n/a | self.assertEqual(-0x0, 0) |
---|
27 | n/a | self.assertEqual(-0x10, -16) |
---|
28 | n/a | self.assertEqual(-0x7fffffff, -2147483647) |
---|
29 | n/a | self.assertEqual(-0x7fffffffffffffff, -9223372036854775807) |
---|
30 | n/a | |
---|
31 | n/a | def test_hex_unsigned(self): |
---|
32 | n/a | # Positive constants |
---|
33 | n/a | self.assertEqual(0x80000000, 2147483648) |
---|
34 | n/a | self.assertEqual(0xffffffff, 4294967295) |
---|
35 | n/a | # Ditto with a minus sign and parentheses |
---|
36 | n/a | self.assertEqual(-(0x80000000), -2147483648) |
---|
37 | n/a | self.assertEqual(-(0xffffffff), -4294967295) |
---|
38 | n/a | # Ditto with a minus sign and NO parentheses |
---|
39 | n/a | # This failed in Python 2.2 through 2.2.2 and in 2.3a1 |
---|
40 | n/a | self.assertEqual(-0x80000000, -2147483648) |
---|
41 | n/a | self.assertEqual(-0xffffffff, -4294967295) |
---|
42 | n/a | |
---|
43 | n/a | # Positive constants |
---|
44 | n/a | self.assertEqual(0x8000000000000000, 9223372036854775808) |
---|
45 | n/a | self.assertEqual(0xffffffffffffffff, 18446744073709551615) |
---|
46 | n/a | # Ditto with a minus sign and parentheses |
---|
47 | n/a | self.assertEqual(-(0x8000000000000000), -9223372036854775808) |
---|
48 | n/a | self.assertEqual(-(0xffffffffffffffff), -18446744073709551615) |
---|
49 | n/a | # Ditto with a minus sign and NO parentheses |
---|
50 | n/a | # This failed in Python 2.2 through 2.2.2 and in 2.3a1 |
---|
51 | n/a | self.assertEqual(-0x8000000000000000, -9223372036854775808) |
---|
52 | n/a | self.assertEqual(-0xffffffffffffffff, -18446744073709551615) |
---|
53 | n/a | |
---|
54 | n/a | def test_oct_baseline(self): |
---|
55 | n/a | # A few upper/lowercase tests |
---|
56 | n/a | self.assertEqual(0o0, 0O0) |
---|
57 | n/a | self.assertEqual(0o1, 0O1) |
---|
58 | n/a | self.assertEqual(0o1234567, 0O1234567) |
---|
59 | n/a | # Baseline tests |
---|
60 | n/a | self.assertEqual(0o0, 0) |
---|
61 | n/a | self.assertEqual(0o20, 16) |
---|
62 | n/a | self.assertEqual(0o17777777777, 2147483647) |
---|
63 | n/a | self.assertEqual(0o777777777777777777777, 9223372036854775807) |
---|
64 | n/a | # Ditto with a minus sign and parentheses |
---|
65 | n/a | self.assertEqual(-(0o0), 0) |
---|
66 | n/a | self.assertEqual(-(0o20), -16) |
---|
67 | n/a | self.assertEqual(-(0o17777777777), -2147483647) |
---|
68 | n/a | self.assertEqual(-(0o777777777777777777777), -9223372036854775807) |
---|
69 | n/a | # Ditto with a minus sign and NO parentheses |
---|
70 | n/a | self.assertEqual(-0o0, 0) |
---|
71 | n/a | self.assertEqual(-0o20, -16) |
---|
72 | n/a | self.assertEqual(-0o17777777777, -2147483647) |
---|
73 | n/a | self.assertEqual(-0o777777777777777777777, -9223372036854775807) |
---|
74 | n/a | |
---|
75 | n/a | def test_oct_unsigned(self): |
---|
76 | n/a | # Positive constants |
---|
77 | n/a | self.assertEqual(0o20000000000, 2147483648) |
---|
78 | n/a | self.assertEqual(0o37777777777, 4294967295) |
---|
79 | n/a | # Ditto with a minus sign and parentheses |
---|
80 | n/a | self.assertEqual(-(0o20000000000), -2147483648) |
---|
81 | n/a | self.assertEqual(-(0o37777777777), -4294967295) |
---|
82 | n/a | # Ditto with a minus sign and NO parentheses |
---|
83 | n/a | # This failed in Python 2.2 through 2.2.2 and in 2.3a1 |
---|
84 | n/a | self.assertEqual(-0o20000000000, -2147483648) |
---|
85 | n/a | self.assertEqual(-0o37777777777, -4294967295) |
---|
86 | n/a | |
---|
87 | n/a | # Positive constants |
---|
88 | n/a | self.assertEqual(0o1000000000000000000000, 9223372036854775808) |
---|
89 | n/a | self.assertEqual(0o1777777777777777777777, 18446744073709551615) |
---|
90 | n/a | # Ditto with a minus sign and parentheses |
---|
91 | n/a | self.assertEqual(-(0o1000000000000000000000), -9223372036854775808) |
---|
92 | n/a | self.assertEqual(-(0o1777777777777777777777), -18446744073709551615) |
---|
93 | n/a | # Ditto with a minus sign and NO parentheses |
---|
94 | n/a | # This failed in Python 2.2 through 2.2.2 and in 2.3a1 |
---|
95 | n/a | self.assertEqual(-0o1000000000000000000000, -9223372036854775808) |
---|
96 | n/a | self.assertEqual(-0o1777777777777777777777, -18446744073709551615) |
---|
97 | n/a | |
---|
98 | n/a | def test_bin_baseline(self): |
---|
99 | n/a | # A few upper/lowercase tests |
---|
100 | n/a | self.assertEqual(0b0, 0B0) |
---|
101 | n/a | self.assertEqual(0b1, 0B1) |
---|
102 | n/a | self.assertEqual(0b10101010101, 0B10101010101) |
---|
103 | n/a | # Baseline tests |
---|
104 | n/a | self.assertEqual(0b0, 0) |
---|
105 | n/a | self.assertEqual(0b10000, 16) |
---|
106 | n/a | self.assertEqual(0b1111111111111111111111111111111, 2147483647) |
---|
107 | n/a | self.assertEqual(0b111111111111111111111111111111111111111111111111111111111111111, 9223372036854775807) |
---|
108 | n/a | # Ditto with a minus sign and parentheses |
---|
109 | n/a | self.assertEqual(-(0b0), 0) |
---|
110 | n/a | self.assertEqual(-(0b10000), -16) |
---|
111 | n/a | self.assertEqual(-(0b1111111111111111111111111111111), -2147483647) |
---|
112 | n/a | self.assertEqual(-(0b111111111111111111111111111111111111111111111111111111111111111), -9223372036854775807) |
---|
113 | n/a | # Ditto with a minus sign and NO parentheses |
---|
114 | n/a | self.assertEqual(-0b0, 0) |
---|
115 | n/a | self.assertEqual(-0b10000, -16) |
---|
116 | n/a | self.assertEqual(-0b1111111111111111111111111111111, -2147483647) |
---|
117 | n/a | self.assertEqual(-0b111111111111111111111111111111111111111111111111111111111111111, -9223372036854775807) |
---|
118 | n/a | |
---|
119 | n/a | def test_bin_unsigned(self): |
---|
120 | n/a | # Positive constants |
---|
121 | n/a | self.assertEqual(0b10000000000000000000000000000000, 2147483648) |
---|
122 | n/a | self.assertEqual(0b11111111111111111111111111111111, 4294967295) |
---|
123 | n/a | # Ditto with a minus sign and parentheses |
---|
124 | n/a | self.assertEqual(-(0b10000000000000000000000000000000), -2147483648) |
---|
125 | n/a | self.assertEqual(-(0b11111111111111111111111111111111), -4294967295) |
---|
126 | n/a | # Ditto with a minus sign and NO parentheses |
---|
127 | n/a | # This failed in Python 2.2 through 2.2.2 and in 2.3a1 |
---|
128 | n/a | self.assertEqual(-0b10000000000000000000000000000000, -2147483648) |
---|
129 | n/a | self.assertEqual(-0b11111111111111111111111111111111, -4294967295) |
---|
130 | n/a | |
---|
131 | n/a | # Positive constants |
---|
132 | n/a | self.assertEqual(0b1000000000000000000000000000000000000000000000000000000000000000, 9223372036854775808) |
---|
133 | n/a | self.assertEqual(0b1111111111111111111111111111111111111111111111111111111111111111, 18446744073709551615) |
---|
134 | n/a | # Ditto with a minus sign and parentheses |
---|
135 | n/a | self.assertEqual(-(0b1000000000000000000000000000000000000000000000000000000000000000), -9223372036854775808) |
---|
136 | n/a | self.assertEqual(-(0b1111111111111111111111111111111111111111111111111111111111111111), -18446744073709551615) |
---|
137 | n/a | # Ditto with a minus sign and NO parentheses |
---|
138 | n/a | # This failed in Python 2.2 through 2.2.2 and in 2.3a1 |
---|
139 | n/a | self.assertEqual(-0b1000000000000000000000000000000000000000000000000000000000000000, -9223372036854775808) |
---|
140 | n/a | self.assertEqual(-0b1111111111111111111111111111111111111111111111111111111111111111, -18446744073709551615) |
---|
141 | n/a | |
---|
142 | n/a | if __name__ == "__main__": |
---|
143 | n/a | unittest.main() |
---|