forked from ArchipelagoMW/Archipelago
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first pass at adding grub count tests
- Loading branch information
Showing
2 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import typing | ||
from argparse import Namespace | ||
from BaseClasses import CollectionState, MultiWorld | ||
from Options import ItemLinks | ||
from test.bases import WorldTestBase | ||
from worlds.AutoWorld import AutoWorldRegister, call_all | ||
from .. import HKWorld | ||
|
||
|
||
class linkedTestHK(): | ||
run_default_tests = False | ||
game = "Hollow Knight" | ||
world: HKWorld | ||
expected_grubs: int | ||
item_link_group: typing.List[typing.Dict[str, typing.Any]] | ||
|
||
def setup_item_links(self, args): | ||
setattr(args, "item_links", | ||
{ | ||
1: ItemLinks.from_any(self.item_link_group), | ||
2: ItemLinks.from_any([{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Grub"], | ||
"link_replacement": False, | ||
"replacement_item": "One_Geo", | ||
}]) | ||
}) | ||
return args | ||
|
||
def world_setup(self) -> None: | ||
""" | ||
Create a multiworld with two players that share an itemlink | ||
""" | ||
self.multiworld = MultiWorld(2) | ||
self.multiworld.game = {1: self.game, 2: self.game} | ||
self.multiworld.player_name = {1: "Linker 1", 2: "Linker 2"} | ||
self.multiworld.set_seed() | ||
args = Namespace() | ||
options_dataclass = AutoWorldRegister.world_types[self.game].options_dataclass | ||
for name, option in options_dataclass.type_hints.items(): | ||
setattr(args, name, { | ||
1: option.from_any(self.options.get(name, option.default)), | ||
2: option.from_any(self.options.get(name, option.default)) | ||
}) | ||
args = self.setup_item_links(args) | ||
self.multiworld.set_options(args) | ||
self.multiworld.set_item_links() | ||
# groups get added to state during its constructor so this has to be after item links are set | ||
self.multiworld.state = CollectionState(self.multiworld) | ||
gen_steps = ("generate_early", "create_regions", "create_items", "set_rules", "generate_basic") | ||
for step in gen_steps: | ||
call_all(self.multiworld, step) | ||
# link the items together and stop at prefill | ||
self.multiworld.link_items() | ||
self.multiworld._all_state = None | ||
call_all(self.multiworld, "pre_fill") | ||
|
||
self.world = self.multiworld.worlds[self.player] | ||
|
||
def test_grub_count(self) -> None: | ||
assert self.world.grub_count == self.expected_grubs, \ | ||
f"Expected {self.expected_grubs} but found {self.world.grub_count}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
from . import linkedTestHK, WorldTestBase | ||
from Options import ItemLinks | ||
|
||
|
||
class test_grubcount_limited(linkedTestHK, WorldTestBase): | ||
options = { | ||
"RandomizeGrubs": True, | ||
"GrubHuntGoal": 20, | ||
"Goal": "any", | ||
} | ||
item_link_group = [{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Grub"], | ||
"link_replacement": True, | ||
"replacement_item": "Grub", | ||
}] | ||
expected_grubs = 20 | ||
|
||
|
||
class test_grubcount_default(linkedTestHK, WorldTestBase): | ||
options = { | ||
"RandomizeGrubs": True, | ||
"Goal": "any", | ||
} | ||
item_link_group = [{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Grub"], | ||
"link_replacement": True, | ||
"replacement_item": "Grub", | ||
}] | ||
expected_grubs = 46 | ||
|
||
|
||
class test_grubcount_all_unlinked(linkedTestHK, WorldTestBase): | ||
options = { | ||
"RandomizeGrubs": True, | ||
"GrubHuntGoal": "all", | ||
"Goal": "any", | ||
} | ||
item_link_group = [] | ||
expected_grubs = 46 | ||
|
||
|
||
class test_grubcount_all_linked(linkedTestHK, WorldTestBase): | ||
options = { | ||
"RandomizeGrubs": True, | ||
"GrubHuntGoal": "all", | ||
"Goal": "any", | ||
} | ||
item_link_group = [{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Grub"], | ||
"link_replacement": True, | ||
"replacement_item": "Grub", | ||
}] | ||
expected_grubs = 46 + 23 | ||
|
||
|
||
class test_replacement_only(linkedTestHK, WorldTestBase): | ||
options = { | ||
"RandomizeGrubs": True, | ||
"GrubHuntGoal": "all", | ||
"Goal": "any", | ||
} | ||
expected_grubs = 46 + 18 # the count of grubs + skills removed from item links | ||
|
||
def setup_item_links(self, args): | ||
setattr(args, "item_links", | ||
{ | ||
1: ItemLinks.from_any([{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Skills"], | ||
"link_replacement": True, | ||
"replacement_item": "Grub", | ||
}]), | ||
2: ItemLinks.from_any([{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Skills"], | ||
"link_replacement": True, | ||
"replacement_item": "Grub", | ||
}]) | ||
}) | ||
return args | ||
|
||
|
||
class test_replacement_only_unlinked(linkedTestHK, WorldTestBase): | ||
options = { | ||
"RandomizeGrubs": True, | ||
"GrubHuntGoal": "all", | ||
"Goal": "any", | ||
} | ||
expected_grubs = 46 + 9 # the count of grubs + half skills removed from item links | ||
|
||
def setup_item_links(self, args): | ||
setattr(args, "item_links", | ||
{ | ||
1: ItemLinks.from_any([{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Skills"], | ||
"link_replacement": False, | ||
"replacement_item": "Grub", | ||
}]), | ||
2: ItemLinks.from_any([{ | ||
"name": "ItemLinkTest", | ||
"item_pool": ["Skills"], | ||
"link_replacement": False, | ||
"replacement_item": "Grub", | ||
}]) | ||
}) | ||
return args |