Skip to content

Commit 14afb67

Browse files
committed
add tests
1 parent f5a6ed3 commit 14afb67

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

bitarray/test_util.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def test_ones_small(self):
10461046
sm += i
10471047
self.assertEqual(sum_indices(a), sm)
10481048

1049-
def test_large(self):
1049+
def test_large_ones(self):
10501050
# Note that this will also work on 32-bit machines, even though
10511051
# for n=100_000, we get: n*(n-1)/2 = 4999950000 > 2**32
10521052
n = 100_000
@@ -1055,6 +1055,12 @@ def test_large(self):
10551055
a.setall(1)
10561056
self.assertEqual(sum_indices(a), n * (n - 1) // 2)
10571057

1058+
def test_large_random(self):
1059+
n = 100_000
1060+
a = urandom_2(n)
1061+
self.assertEqual(sum_indices(a),
1062+
sum(i for i, v in enumerate(a) if v))
1063+
10581064
def test_random(self):
10591065
for a in self.randombitarrays():
10601066
res = sum_indices(a)
@@ -1092,6 +1098,14 @@ def test_ones(self):
10921098
if i < 19:
10931099
self.assertEqual(lst[i], x)
10941100

1101+
def test_large_random(self):
1102+
n = 100_000
1103+
a = urandom_2(n)
1104+
self.assertEqual(
1105+
xor_indices(a),
1106+
reduce(operator.xor, (i for i, v in enumerate(a) if v))
1107+
)
1108+
10951109
def test_random(self):
10961110
for a in self.randombitarrays():
10971111
cnt = a.count()

devel/test_random.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,6 @@ def test_stat(self):
218218
# p = 0.522195 mean = 52219.451858 stdev = 157.958033
219219
self.assertTrue(abs(x - 52_219) <= 1_580)
220220

221-
def test_sums(self):
222-
# not so much a test for urandom itself, but for sum_indices()
223-
# and xor_indices() for large bitarray
224-
n = 10_000_000
225-
a = urandom(n, choice(["little", "big"]))
226-
indices = [i for i, v in enumerate(a) if v]
227-
self.assertEqual(sum_indices(a), sum(indices))
228-
self.assertEqual(xor_indices(a), reduce(operator.xor, indices))
229-
230221

231222
class Random_K_Tests(Util):
232223

examples/README

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ puff/
8282
https://github.com/madler/zlib/blob/master/contrib/puff/puff.c
8383

8484

85-
resize/
86-
Things to study the bitarray resize function, including the growth
87-
pattern it creates and tests for the current implementation.
88-
89-
9085
sieve.py
9186
Demonstrates the "Sieve of Eratosthenes" algorithm for finding all prime
9287
numbers up to a specified integer.

0 commit comments

Comments
 (0)