|
| 1 | +# Copyright (c) 2019 - 2025, Ilan Schnell; All Rights Reserved |
| 2 | +# bitarray is published under the PSF license. |
| 3 | +# |
| 4 | +# Author: Ilan Schnell |
1 | 5 | """ |
2 | 6 | Tests for bitarray.util module |
3 | 7 | """ |
@@ -526,7 +530,7 @@ def test_file(self): |
526 | 530 | finally: |
527 | 531 | shutil.rmtree(tmpdir) |
528 | 532 |
|
529 | | -# --------------------------------------------------------------------------- |
| 533 | +# ----------------------------- strip() ----------------------------------- |
530 | 534 |
|
531 | 535 | class StripTests(unittest.TestCase, Util): |
532 | 536 |
|
@@ -593,7 +597,7 @@ def test_one_set(self): |
593 | 597 | self.assertEqual(strip(a, 'both'), bitarray('1')) |
594 | 598 | self.assertEqual(len(a), n) |
595 | 599 |
|
596 | | -# --------------------------------------------------------------------------- |
| 600 | +# ----------------------------- count_n() --------------------------------- |
597 | 601 |
|
598 | 602 | class CountN_Tests(unittest.TestCase, Util): |
599 | 603 |
|
@@ -710,9 +714,10 @@ def test_primes(self): |
710 | 714 | a = gen_primes(10_000) |
711 | 715 | # there are 1229 primes below 10,000 |
712 | 716 | self.assertEqual(a.count(), 1229) |
713 | | - n = count_n(a, 1_000) - 1 |
714 | | - # the thousandth prime number is 7919 |
715 | | - self.assertEqual(n, 7919) |
| 717 | + for n, p in [( 10, 29), # the 10th prime number is 29 |
| 718 | + ( 100, 541), # the 100th prime number is 541 |
| 719 | + (1000, 7919)]: # the 1000th prime number is 7919 |
| 720 | + self.assertEqual(count_n(a, n) - 1, p) |
716 | 721 |
|
717 | 722 | def test_large(self): |
718 | 723 | for _ in range(100): |
@@ -818,7 +823,7 @@ def test_misc(self): |
818 | 823 | self.assertEqual(all(a ^ b), count_xor(a, b) == n) |
819 | 824 | self.assertEqual(all(a ^ b), a == ~b) |
820 | 825 |
|
821 | | -# --------------------------------------------------------------------------- |
| 826 | +# --------------------------- any_and() ----------------------------------- |
822 | 827 |
|
823 | 828 | class BitwiseAnyTests(unittest.TestCase, Util): |
824 | 829 |
|
@@ -901,7 +906,7 @@ def test_one(self): |
901 | 906 | a[i] = 1 |
902 | 907 | self.assertEqual(b[i], any_and(a, b)) |
903 | 908 |
|
904 | | -# --------------------------------------------------------------------------- |
| 909 | +# ---------------------------- subset() ----------------------------------- |
905 | 910 |
|
906 | 911 | class SubsetTests(unittest.TestCase, Util): |
907 | 912 |
|
@@ -950,7 +955,7 @@ def test_random(self): |
950 | 955 | a.setall(1) |
951 | 956 | self.check(b, a, True) |
952 | 957 |
|
953 | | -# --------------------------------------------------------------------------- |
| 958 | +# ------------------------- correspond_all() ------------------------------ |
954 | 959 |
|
955 | 960 | class CorrespondAllTests(unittest.TestCase): |
956 | 961 |
|
@@ -988,10 +993,10 @@ def test_random(self): |
988 | 993 | self.assertEqual(res[1] + res[2], count_xor(a, b)) |
989 | 994 | self.assertEqual(sum(res), n) |
990 | 995 |
|
991 | | -# --------------------------------------------------------------------------- |
| 996 | +# ----------------------------- byteswap() -------------------------------- |
992 | 997 |
|
993 | 998 | @skipIf(is_pypy) |
994 | | -class ByteswapTests(unittest.TestCase): |
| 999 | +class ByteSwapTests(unittest.TestCase): |
995 | 1000 |
|
996 | 1001 | def test_basic_bytearray(self): |
997 | 1002 | a = bytearray(b"ABCD") |
@@ -1086,7 +1091,7 @@ def test_reverse_bitarray(self): |
1086 | 1091 | a.bytereverse() |
1087 | 1092 | self.assertEqual(a, b[::-1]) |
1088 | 1093 |
|
1089 | | -# --------------------------------------------------------------------------- |
| 1094 | +# ------------------------------ parity() --------------------------------- |
1090 | 1095 |
|
1091 | 1096 | class ParityTests(unittest.TestCase): |
1092 | 1097 |
|
@@ -1119,7 +1124,7 @@ def test_wrong_args(self): |
1119 | 1124 | self.assertRaises(TypeError, parity) |
1120 | 1125 | self.assertRaises(TypeError, parity, bitarray("110"), 1) |
1121 | 1126 |
|
1122 | | -# --------------------------------------------------------------------------- |
| 1127 | +# ---------------------------- sum_indices() ------------------------------ |
1123 | 1128 |
|
1124 | 1129 | class SumIndicesUtil(unittest.TestCase): |
1125 | 1130 |
|
@@ -2404,7 +2409,7 @@ def test_bitwise_inplace(self): |
2404 | 2409 | c <<= n |
2405 | 2410 | self.assertEqual(ba2int(c), i << n) |
2406 | 2411 |
|
2407 | | -# --------------------------------------------------------------------------- |
| 2412 | +# ---------------------- serialize() deserialize() ----------------------- |
2408 | 2413 |
|
2409 | 2414 | class SerializationTests(unittest.TestCase, Util): |
2410 | 2415 |
|
|
0 commit comments