forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helpers.py
83 lines (68 loc) · 3.48 KB
/
test_helpers.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
81
82
83
import unittest
from typing import Callable, Dict, Optional
from BaseClasses import CollectionState, MultiWorld, Region
class TestHelpers(unittest.TestCase):
multiworld: MultiWorld
player: int = 1
def setUp(self) -> None:
self.multiworld = MultiWorld(self.player)
self.multiworld.game[self.player] = "helper_test_game"
self.multiworld.player_name = {1: "Tester"}
self.multiworld.set_seed()
def test_region_helpers(self) -> None:
"""Tests `Region.add_locations()` and `Region.add_exits()` have correct behavior"""
regions: Dict[str, str] = {
"TestRegion1": "I'm an apple",
"TestRegion2": "I'm a banana",
"TestRegion3": "Empty Region",
}
locations: Dict[str, Dict[str, Optional[int]]] = {
"TestRegion1": {
"loc_1": 123,
"loc_2": 456,
"event_loc": None,
},
"TestRegion2": {
"loc_3": 321,
"loc_4": 654,
}
}
reg_exits: Dict[str, Dict[str, Optional[str]]] = {
"TestRegion1": {"TestRegion2": "connection"},
"TestRegion2": {"TestRegion1": None},
}
reg_exit_set: Dict[str, set[str]] = {
"TestRegion1": {"TestRegion3"}
}
exit_rules: Dict[str, Callable[[CollectionState], bool]] = {
"TestRegion1": lambda state: state.has("test_item", self.player)
}
self.multiworld.regions += [Region(region, self.player, self.multiworld, regions[region]) for region in regions]
with self.subTest("Test Location Creation Helper"):
for region, loc_pair in locations.items():
self.multiworld.get_region(region, self.player).add_locations(loc_pair)
created_location_names = [loc.name for loc in self.multiworld.get_locations()]
for loc_pair in locations.values():
for loc_name in loc_pair:
self.assertTrue(loc_name in created_location_names)
with self.subTest("Test Exit Creation Helper"):
for region, exit_dict in reg_exits.items():
self.multiworld.get_region(region, self.player).add_exits(exit_dict, exit_rules)
created_exit_names = [exit.name for region in self.multiworld.get_regions() for exit in region.exits]
for parent, exit_pair in reg_exits.items():
for exit_reg, exit_name in exit_pair.items():
if exit_name:
self.assertTrue(exit_name in created_exit_names)
else:
self.assertTrue(f"{parent} -> {exit_reg}" in created_exit_names)
if exit_reg in exit_rules:
entrance_name = exit_name if exit_name else f"{parent} -> {exit_reg}"
self.assertEqual(exit_rules[exit_reg],
self.multiworld.get_entrance(entrance_name, self.player).access_rule)
for region in reg_exit_set:
current_region = self.multiworld.get_region(region, self.player)
current_region.add_exits(reg_exit_set[region])
exit_names = {_exit.name for _exit in current_region.exits}
for reg_exit in reg_exit_set[region]:
self.assertTrue(f"{region} -> {reg_exit}" in exit_names,
f"{region} -> {reg_exit} not in {exit_names}")