-
Notifications
You must be signed in to change notification settings - Fork 161
Expand file tree
/
Copy pathtest_inner.py
More file actions
71 lines (56 loc) · 2.06 KB
/
test_inner.py
File metadata and controls
71 lines (56 loc) · 2.06 KB
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
63
64
65
66
67
68
69
70
71
from __future__ import annotations
from itertools import count
from typing import TYPE_CHECKING
import pytest
from pyk.kast.inner import KVariable, flatten_label, keep_vars_sorted
from ..utils import a, f, g, x, y, z
if TYPE_CHECKING:
from typing import Final
from pyk.kast import KInner
FLATTEN_LABEL_DATA: Final[tuple[tuple[str, KInner, list[KInner]], ...]] = (
('a', a, []),
('b', a, [a]),
('x', x, [x]),
('y', x, [x]),
('f', f(x), [x]),
('g', f(x), [f(x)]),
('f', f(x, y), [x, y]),
('f', f(x, x), [x, x]),
('f', f(x, y, z), [x, y, z]),
('f', f(f(x)), [x]),
('f', f(f(f(x))), [x]),
('f', f(g(f(x))), [g(f(x))]),
('f', f(f(x, y, z)), [x, y, z]),
('f', f(x, f(y, x, f(y)), z), [x, y, x, y, z]),
('f', f(x, f(y, x, f(g(f(y))), z)), [x, y, x, g(f(y)), z]),
)
@pytest.mark.parametrize('label,kast,expected', FLATTEN_LABEL_DATA, ids=count())
def test_flatten_label(label: str, kast: KInner, expected: list[KInner]) -> None:
# When
actual = flatten_label(label, kast)
# Then
assert actual == expected
KEEP_VARS_SORTED_DATA: Final[tuple[tuple[dict[str, list[KVariable]], dict[str, KVariable]], ...]] = (
(
{'a': [KVariable('a'), KVariable('a')], 'b': [KVariable('b'), KVariable('b')]},
{'a': KVariable('a'), 'b': KVariable('b')},
),
(
{'a': [KVariable('a', 'K'), KVariable('a', 'X')], 'b': [KVariable('b', 'K'), KVariable('b', 'X')]},
{'a': KVariable('a'), 'b': KVariable('b')},
),
(
{'a': [KVariable('a', 'K'), KVariable('a')], 'b': [KVariable('b', 'K'), KVariable('b', 'K')]},
{'a': KVariable('a', 'K'), 'b': KVariable('b', 'K')},
),
(
{'a': [KVariable('a', 'A'), KVariable('a'), KVariable('a', 'B')]},
{'a': KVariable('a')},
),
)
@pytest.mark.parametrize('occurrences,expected', KEEP_VARS_SORTED_DATA, ids=count())
def test_keep_vars_sorted(occurrences: dict[str, list[KVariable]], expected: dict[str, KVariable]) -> None:
# When
actual = keep_vars_sorted(occurrences)
# Then
assert actual == expected