File: resize.py

package info (click to toggle)
python-bitarray 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,288 kB
  • sloc: python: 11,456; ansic: 7,657; makefile: 73; sh: 6
file content (42 lines) | stat: -rw-r--r-- 705 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from bitarray import bitarray

from test_resize import get_alloc, resize, show


s = 290797
def bbs():
    global s
    s = pow(s, 2, 50515093)
    return s % 8000

a = bitarray()
prev = -1
while len(a) < 1_000:
    alloc = get_alloc(a)
    if prev != alloc:
        show(a)
    prev = alloc
    a.append(1)

for i in 800_000, 400_000, 399_992, 500_000, 0, 0, 10_000, 400, 600, 2_000:
    resize(a, i)
    assert len(a) == i
    show(a)

while len(a):
    alloc = get_alloc(a)
    if prev != alloc:
        show(a)
    prev = alloc
    a.pop()

show(a)

for nbits in range(0, 100, 8):
    a = bitarray()
    a.extend(bitarray(nbits))
    show(a)

for _ in range(100_000):
    resize(a, bbs())
    show(a)