ยปCore Development>Code coverage>Lib/test/test_int_literal.py

Python code coverage for Lib/test/test_int_literal.py

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