Tests: now autoload tests from /worlds/*/test (#1318)
Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
149
worlds/zillion/test/TestGoal.py
Normal file
149
worlds/zillion/test/TestGoal.py
Normal file
@@ -0,0 +1,149 @@
|
||||
from . import ZillionTestBase
|
||||
|
||||
|
||||
class TestGoalVanilla(ZillionTestBase):
|
||||
options = {
|
||||
"start_char": "JJ",
|
||||
"jump_levels": "vanilla",
|
||||
"gun_levels": "vanilla",
|
||||
"floppy_disk_count": 7,
|
||||
"floppy_req": 6,
|
||||
}
|
||||
|
||||
def test_floppies(self) -> None:
|
||||
self.collect_by_name(["Apple", "Champ", "Red ID Card"])
|
||||
self.assertBeatable(False) # 0 floppies
|
||||
floppies = self.get_items_by_name("Floppy Disk")
|
||||
win = self.get_item_by_name("Win")
|
||||
self.collect(floppies[:-2]) # 1 too few
|
||||
self.assertEqual(self.count("Floppy Disk"), 5)
|
||||
self.assertBeatable(False)
|
||||
self.collect(floppies[-2:-1]) # exact
|
||||
self.assertEqual(self.count("Floppy Disk"), 6)
|
||||
self.assertBeatable(True)
|
||||
self.remove([win]) # reset
|
||||
self.collect(floppies[-1:]) # 1 extra
|
||||
self.assertEqual(self.count("Floppy Disk"), 7)
|
||||
self.assertBeatable(True)
|
||||
|
||||
def test_with_everything(self) -> None:
|
||||
self.collect_by_name(["Apple", "Champ", "Red ID Card", "Floppy Disk"])
|
||||
self.assertBeatable(True)
|
||||
|
||||
def test_no_jump(self) -> None:
|
||||
self.collect_by_name(["Champ", "Red ID Card", "Floppy Disk"])
|
||||
self.assertBeatable(False)
|
||||
|
||||
def test_no_gun(self) -> None:
|
||||
self.ensure_gun_3_requirement()
|
||||
self.collect_by_name(["Apple", "Red ID Card", "Floppy Disk"])
|
||||
self.assertBeatable(False)
|
||||
|
||||
def test_no_red(self) -> None:
|
||||
self.collect_by_name(["Apple", "Champ", "Floppy Disk"])
|
||||
self.assertBeatable(False)
|
||||
|
||||
|
||||
class TestGoalBalanced(ZillionTestBase):
|
||||
options = {
|
||||
"start_char": "JJ",
|
||||
"jump_levels": "balanced",
|
||||
"gun_levels": "balanced",
|
||||
}
|
||||
|
||||
def test_jump(self) -> None:
|
||||
self.collect_by_name(["Red ID Card", "Floppy Disk", "Zillion"])
|
||||
self.assertBeatable(False) # not enough jump
|
||||
opas = self.get_items_by_name("Opa-Opa")
|
||||
self.collect(opas[:1]) # too few
|
||||
self.assertEqual(self.count("Opa-Opa"), 1)
|
||||
self.assertBeatable(False)
|
||||
self.collect(opas[1:])
|
||||
self.assertBeatable(True)
|
||||
|
||||
def test_guns(self) -> None:
|
||||
self.ensure_gun_3_requirement()
|
||||
self.collect_by_name(["Red ID Card", "Floppy Disk", "Opa-Opa"])
|
||||
self.assertBeatable(False) # not enough gun
|
||||
guns = self.get_items_by_name("Zillion")
|
||||
self.collect(guns[:1]) # too few
|
||||
self.assertEqual(self.count("Zillion"), 1)
|
||||
self.assertBeatable(False)
|
||||
self.collect(guns[1:])
|
||||
self.assertBeatable(True)
|
||||
|
||||
|
||||
class TestGoalRestrictive(ZillionTestBase):
|
||||
options = {
|
||||
"start_char": "JJ",
|
||||
"jump_levels": "restrictive",
|
||||
"gun_levels": "restrictive",
|
||||
}
|
||||
|
||||
def test_jump(self) -> None:
|
||||
self.collect_by_name(["Champ", "Red ID Card", "Floppy Disk", "Zillion"])
|
||||
self.assertBeatable(False) # not enough jump
|
||||
self.collect_by_name("Opa-Opa")
|
||||
self.assertBeatable(False) # with all opas, jj champ can't jump
|
||||
self.collect_by_name("Apple")
|
||||
self.assertBeatable(True)
|
||||
|
||||
def test_guns(self) -> None:
|
||||
self.ensure_gun_3_requirement()
|
||||
self.collect_by_name(["Apple", "Red ID Card", "Floppy Disk", "Opa-Opa"])
|
||||
self.assertBeatable(False) # not enough gun
|
||||
self.collect_by_name("Zillion")
|
||||
self.assertBeatable(False) # with all guns, jj apple can't gun
|
||||
self.collect_by_name("Champ")
|
||||
self.assertBeatable(True)
|
||||
|
||||
|
||||
class TestGoalAppleStart(ZillionTestBase):
|
||||
""" creation of character rescue items has some special interactions with logic """
|
||||
options = {
|
||||
"start_char": "Apple",
|
||||
"jump_levels": "balanced",
|
||||
"gun_levels": "low",
|
||||
"zillion_count": 5
|
||||
}
|
||||
|
||||
def test_guns_jj_first(self) -> None:
|
||||
""" with low gun levels, 5 Zillion is enough to get JJ to gun 3 """
|
||||
self.ensure_gun_3_requirement()
|
||||
self.collect_by_name(["JJ", "Red ID Card", "Floppy Disk", "Opa-Opa"])
|
||||
self.assertBeatable(False) # not enough gun
|
||||
self.collect_by_name("Zillion")
|
||||
self.assertBeatable(True)
|
||||
|
||||
def test_guns_zillions_first(self) -> None:
|
||||
""" with low gun levels, 5 Zillion is enough to get JJ to gun 3 """
|
||||
self.ensure_gun_3_requirement()
|
||||
self.collect_by_name(["Zillion", "Red ID Card", "Floppy Disk", "Opa-Opa"])
|
||||
self.assertBeatable(False) # not enough gun
|
||||
self.collect_by_name("JJ")
|
||||
self.assertBeatable(True)
|
||||
|
||||
|
||||
class TestGoalChampStart(ZillionTestBase):
|
||||
""" creation of character rescue items has some special interactions with logic """
|
||||
options = {
|
||||
"start_char": "Champ",
|
||||
"jump_levels": "low",
|
||||
"gun_levels": "balanced",
|
||||
"opa_opa_count": 5,
|
||||
"opas_per_level": 1
|
||||
}
|
||||
|
||||
def test_jump_jj_first(self) -> None:
|
||||
""" with low jump levels, 5 level-ups is enough to get JJ to jump 3 """
|
||||
self.collect_by_name(["JJ", "Red ID Card", "Floppy Disk", "Zillion"])
|
||||
self.assertBeatable(False) # not enough jump
|
||||
self.collect_by_name("Opa-Opa")
|
||||
self.assertBeatable(True)
|
||||
|
||||
def test_jump_opa_first(self) -> None:
|
||||
""" with low jump levels, 5 level-ups is enough to get JJ to jump 3 """
|
||||
self.collect_by_name(["Opa-Opa", "Red ID Card", "Floppy Disk", "Zillion"])
|
||||
self.assertBeatable(False) # not enough jump
|
||||
self.collect_by_name("JJ")
|
||||
self.assertBeatable(True)
|
||||
26
worlds/zillion/test/TestOptions.py
Normal file
26
worlds/zillion/test/TestOptions.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from . import ZillionTestBase
|
||||
|
||||
from worlds.zillion.options import ZillionJumpLevels, ZillionGunLevels, validate
|
||||
from zilliandomizer.options import VBLR_CHOICES
|
||||
|
||||
|
||||
class OptionsTest(ZillionTestBase):
|
||||
auto_construct = False
|
||||
|
||||
def test_validate_default(self) -> None:
|
||||
self.world_setup()
|
||||
validate(self.multiworld, 1)
|
||||
|
||||
def test_vblr_ap_to_zz(self) -> None:
|
||||
""" all of the valid values for the AP options map to valid values for ZZ options """
|
||||
for option_name, vblr_class in (
|
||||
("jump_levels", ZillionJumpLevels),
|
||||
("gun_levels", ZillionGunLevels)
|
||||
):
|
||||
for value in vblr_class.name_lookup.values():
|
||||
self.options = {option_name: value}
|
||||
self.world_setup()
|
||||
zz_options, _item_counts = validate(self.multiworld, 1)
|
||||
assert getattr(zz_options, option_name) in VBLR_CHOICES
|
||||
|
||||
# TODO: test validate with invalid combinations of options
|
||||
29
worlds/zillion/test/TestReproducibleRandom.py
Normal file
29
worlds/zillion/test/TestReproducibleRandom.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from typing import cast
|
||||
from . import ZillionTestBase
|
||||
|
||||
from worlds.zillion import ZillionWorld
|
||||
|
||||
|
||||
class SeedTest(ZillionTestBase):
|
||||
auto_construct = False
|
||||
|
||||
def test_reproduce_seed(self) -> None:
|
||||
self.world_setup(42)
|
||||
z_world = cast(ZillionWorld, self.multiworld.worlds[1])
|
||||
r = z_world.zz_system.randomizer
|
||||
assert r
|
||||
randomized_requirements_first = tuple(
|
||||
location.req.gun
|
||||
for location in r.locations.values()
|
||||
)
|
||||
|
||||
self.world_setup(42)
|
||||
z_world = cast(ZillionWorld, self.multiworld.worlds[1])
|
||||
r = z_world.zz_system.randomizer
|
||||
assert r
|
||||
randomized_requirements_second = tuple(
|
||||
location.req.gun
|
||||
for location in r.locations.values()
|
||||
)
|
||||
|
||||
assert randomized_requirements_first == randomized_requirements_second
|
||||
20
worlds/zillion/test/__init__.py
Normal file
20
worlds/zillion/test/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from typing import cast
|
||||
from test.TestBase import WorldTestBase
|
||||
from worlds.zillion import ZillionWorld
|
||||
|
||||
|
||||
class ZillionTestBase(WorldTestBase):
|
||||
game = "Zillion"
|
||||
|
||||
def ensure_gun_3_requirement(self) -> None:
|
||||
"""
|
||||
There's a low probability that gun 3 is not required.
|
||||
|
||||
This makes sure that gun 3 is required by making all the canisters
|
||||
in O-7 (including key word canisters) require gun 3.
|
||||
"""
|
||||
zz_world = cast(ZillionWorld, self.multiworld.worlds[1])
|
||||
assert zz_world.zz_system.randomizer
|
||||
for zz_loc_name, zz_loc in zz_world.zz_system.randomizer.locations.items():
|
||||
if zz_loc_name.startswith("r15c6"):
|
||||
zz_loc.req.gun = 3
|
||||
Reference in New Issue
Block a user