-
Notifications
You must be signed in to change notification settings - Fork 3
/
cases.py
80 lines (71 loc) · 1.82 KB
/
cases.py
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
72
73
74
75
76
77
78
79
80
import random
from functools import partial
from typing import Iterable
from crosshash import MAX_SAFE_INTEGER, JSON
from tests import gen
# Configuration of generated test cases
GEN_NUM_CASES = 100
GEN_DICT_MAX_DEPTH = 10
GEN_MAX_HEIGHT = 10
GEN_MAX_STR_LEN = 10
GEN_MAX_NUMBER = MAX_SAFE_INTEGER
GENERATORS = (
partial(gen.random_string, max_len=GEN_MAX_STR_LEN),
partial(gen.random_int, max_val=GEN_MAX_NUMBER),
gen.random_bool,
partial(gen.random_float, max_size=GEN_MAX_NUMBER),
)
GENERATORS = (
*GENERATORS,
partial(gen.random_list, GENERATORS),
)
# Manual test cases that should be cross-hashable
CASES_OK: list[JSON] = [
-1.1,
-1,
-1.0,
-1.1,
0,
0.1,
1,
1.0,
'',
'\0',
'AAA',
'بايثون',
'ジャバスクリプト',
'🚀👨⚖️👩🏼🔬',
True,
False,
None,
[1, 2, 3, 'AAA', 'BBB', 'CCC'],
[],
{},
{'empty': ''},
{'float_with_fraction': 1.1},
{'float_with_no_fraction': 1.0},
{'emojis': '🚀👨⚖️👩🏼🔬'},
{'non_latin': 'čćžšđ'},
{'null_character': '\0'},
]
# Manual test cases that shouldn’t be cross-hashable due to unsafe numbers
CASES_UNSAFE_NUMBERS: list[JSON] = [
{'unsafe_int': MAX_SAFE_INTEGER + 1},
{'unsafe_int_neg': -(MAX_SAFE_INTEGER + 1)},
{'unsafe_float': MAX_SAFE_INTEGER + 1.1},
{'unsafe_float_neg': -(MAX_SAFE_INTEGER + 1.1)},
]
def generate_cases(
max_depth=GEN_DICT_MAX_DEPTH,
max_height=GEN_MAX_HEIGHT,
num_cases=GEN_NUM_CASES,
generators=GENERATORS,
) -> Iterable[dict[str, JSON]]:
return (
gen.random_dict(
max_depth=random.randint(1, max_depth),
max_height=random.randint(1, max_height),
generators=generators,
)
for _ in range(num_cases)
)