summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_doctest.py3
-rw-r--r--Lib/test/test_long.py11
2 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 3efe5da..8d9f872 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -669,7 +669,7 @@ plain ol' Python and is guaranteed to be available.
True
>>> real_tests = [t for t in tests if len(t.examples) > 0]
>>> len(real_tests) # objects that actually have doctests
- 13
+ 14
>>> for t in real_tests:
... print('{} {}'.format(len(t.examples), t.name))
...
@@ -682,6 +682,7 @@ plain ol' Python and is guaranteed to be available.
1 builtins.hex
1 builtins.int
3 builtins.int.as_integer_ratio
+ 2 builtins.int.bit_count
2 builtins.int.bit_length
5 builtins.memoryview.hex
1 builtins.oct
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 7ce37e8..c97842b 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -1016,6 +1016,17 @@ class LongTest(unittest.TestCase):
self.assertEqual((a+1).bit_length(), i+1)
self.assertEqual((-a-1).bit_length(), i+1)
+ def test_bit_count(self):
+ for a in range(-1000, 1000):
+ self.assertEqual(a.bit_count(), bin(a).count("1"))
+
+ for exp in [10, 17, 63, 64, 65, 1009, 70234, 1234567]:
+ a = 2**exp
+ self.assertEqual(a.bit_count(), 1)
+ self.assertEqual((a - 1).bit_count(), exp)
+ self.assertEqual((a ^ 63).bit_count(), 7)
+ self.assertEqual(((a - 1) ^ 510).bit_count(), exp - 8)
+
def test_round(self):
# check round-half-even algorithm. For round to nearest ten;
# rounding map is invariant under adding multiples of 20