File: test_resumecode.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (62 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (7)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from rpython.jit.metainterp.resumecode import create_numbering,\
    unpack_numbering, Reader, Writer
from rpython.rtyper.lltypesystem import lltype

from hypothesis import strategies, given, example

examples = [
    [1, 2, 3, 4, 257, 10000, 13, 15],
    [1, 2, 3, 4],
    range(1, 10, 2),
    [13000, 12000, 10000, 256, 255, 254, 257, -3, -1000]
]

def hypothesis_and_examples(func):
    func = given(strategies.lists(strategies.integers(-2**15, 2**15-1)))(func)
    for ex in examples:
        func = example(ex)(func)
    return func

@hypothesis_and_examples
def test_roundtrip(l):
    n = create_numbering(l)
    assert unpack_numbering(n) == l

@hypothesis_and_examples
def test_compressing(l):
    n = create_numbering(l)
    assert len(n.code) <= len(l) * 3

@hypothesis_and_examples
def test_reader(l):
    n = create_numbering(l)
    r = Reader(n)
    for i, elt in enumerate(l):
        assert r.items_read == i
        item = r.next_item()
        assert elt == item

@hypothesis_and_examples
def test_writer(l):
    for size in [len(l), 0]:
        w = Writer(len(l))
        for num in l:
            w.append_int(num)
        n = w.create_numbering()
        assert unpack_numbering(n) == l

@hypothesis_and_examples
def test_patch(l):
    for middle in range(len(l)):
        l1 = l[:middle]
        l2 = l[middle:]
        w = Writer(len(l))
        w.append_int(0)
        for num in l1:
            w.append_int(num)
        w.patch_current_size(0)
        for num in l2:
            w.append_int(num)
        n = w.create_numbering()
        assert unpack_numbering(n)[1:] == l
        assert unpack_numbering(n)[0] == middle + 1