-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_task.py
64 lines (59 loc) · 1.99 KB
/
test_task.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
import random
import pathlib
from synth.syntax.type_system import INT
from synth.syntax.type_helper import FunctionType
from synth.syntax.program import Variable
from synth.task import Task, Dataset
from synth.specification import PBE, Example
def test_dataset_save_and_load(tmp_path: pathlib.Path) -> None:
file_path = tmp_path / "dataset.pickle"
random.seed(0)
dataset = Dataset(
[
Task(
FunctionType(INT, INT, INT),
PBE(
[
Example(
[random.randint(0, 100), random.randint(0, 100)],
random.randint(0, 100),
)
for _ in range(5)
]
),
Variable(0, INT) if random.random() > 0.5 else None,
metadata={"index": i},
)
for i in range(100)
],
metadata={"something": False, "else": "is", "coming": 42},
)
dataset.save(file_path.as_posix())
loaded = Dataset[PBE].load(file_path.as_posix())
assert dataset == loaded
def test_dataset_behaviour() -> None:
random.seed(0)
dataset = Dataset(
[
Task(
FunctionType(INT, INT, INT),
PBE(
[
Example(
[random.randint(0, 100), random.randint(0, 100)],
random.randint(0, 100),
)
for _ in range(5)
]
),
Variable(0, INT) if random.random() > 0.5 else None,
metadata={"index": i},
)
for i in range(100)
],
metadata={"something": False, "else": "is", "coming": 42},
)
assert dataset[0] == dataset.tasks[0]
assert dataset[-5:-1] == dataset.tasks[-5:-1]
assert dataset.tasks == [x for x in dataset]
assert len(dataset) == len(dataset.tasks)