Skip to content

Commit

Permalink
Add tests for the desired behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
agilbert1412 committed Nov 9, 2024
1 parent aae8b16 commit c27d851
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions worlds/stardew_valley/test/assertion/rule_assert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import List
from unittest import TestCase

from BaseClasses import CollectionState, Location
Expand All @@ -14,6 +15,10 @@ def assert_rule_true(self, rule: StardewRule, state: CollectionState):
raise AssertionError(f"Error while checking rule {rule}: {e}"
f"\nExplanation: {expl}")

def assert_rules_true(self, rules: List[StardewRule], state: CollectionState):
for rule in rules:
self.assert_rule_true(rule, state)

def assert_rule_false(self, rule: StardewRule, state: CollectionState):
expl = explain(rule, state, expected=False)
try:
Expand All @@ -22,6 +27,10 @@ def assert_rule_false(self, rule: StardewRule, state: CollectionState):
raise AssertionError(f"Error while checking rule {rule}: {e}"
f"\nExplanation: {expl}")

def assert_rules_false(self, rules: List[StardewRule], state: CollectionState):
for rule in rules:
self.assert_rule_false(rule, state)

def assert_rule_can_be_resolved(self, rule: StardewRule, complete_state: CollectionState):
expl = explain(rule, complete_state)
try:
Expand Down
1 change: 1 addition & 0 deletions worlds/stardew_valley/test/rules/TestBundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_raccoon_bundles_rely_on_previous_ones(self):
self.collect("Mushroom Boxes")
self.collect("Progressive Fishing Rod", 4)
self.collect("Fishing Level", 10)
self.collect("Furnace Recipe")

self.assertFalse(raccoon_rule_1(self.multiworld.state))
self.assertFalse(raccoon_rule_3(self.multiworld.state))
Expand Down
34 changes: 34 additions & 0 deletions worlds/stardew_valley/test/rules/TestCraftingRecipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ def test_can_craft_festival_recipe(self):
self.multiworld.state.collect(self.create_item("Jack-O-Lantern Recipe"), prevent_sweep=False)
self.assert_rule_true(rule, self.multiworld.state)

def test_require_furnace_recipe_for_smelting_checks(self):
locations = ["Craft Furnace", "Smelting", "Copper Pickaxe Upgrade", "Gold Trash Can Upgrade"]
rules = [self.world.logic.region.can_reach_location(location) for location in locations]
self.collect([self.create_item("Progressive Pickaxe")] * 4)
self.collect([self.create_item("Progressive Fishing Rod")] * 4)
self.collect([self.create_item("Progressive Sword")] * 4)
self.collect([self.create_item("Progressive Mine Elevator")] * 24)
self.collect([self.create_item("Progressive Trash Can")] * 2)
self.collect([self.create_item("Mining Level")] * 10)
self.collect([self.create_item("Combat Level")] * 10)
self.collect([self.create_item("Fishing Level")] * 10)
self.collect_all_the_money()
self.assert_rules_false(rules, self.multiworld.state)

self.multiworld.state.collect(self.create_item("Furnace Recipe"), prevent_sweep=False)
self.assert_rules_true(rules, self.multiworld.state)


class TestCraftsanityWithFestivalsLogic(SVTestBase):
options = {
Expand Down Expand Up @@ -101,6 +118,23 @@ def test_can_craft_festival_recipe(self):
self.collect([self.create_item("Progressive Season")] * 2)
self.assert_rule_true(rule, self.multiworld.state)

def test_requires_mining_level_1_for_smelting_checks(self):
locations = ["Smelting", "Copper Pickaxe Upgrade", "Gold Trash Can Upgrade"]
rules = [self.world.logic.region.can_reach_location(location) for location in locations]
self.collect([self.create_item("Progressive Pickaxe")] * 4)
self.collect([self.create_item("Progressive Fishing Rod")] * 4)
self.collect([self.create_item("Progressive Sword")] * 4)
self.collect([self.create_item("Progressive Mine Elevator")] * 24)
self.collect([self.create_item("Progressive Trash Can")] * 2)
self.multiworld.state.collect(self.create_item("Furnace Recipe"), prevent_sweep=False)
self.collect([self.create_item("Combat Level")] * 10)
self.collect([self.create_item("Fishing Level")] * 10)
self.collect_all_the_money()
self.assert_rules_false(rules, self.multiworld.state)

self.collect([self.create_item("Mining Level")] * 10)
self.assert_rules_true(rules, self.multiworld.state)


class TestNoCraftsanityWithFestivalsLogic(SVTestBase):
options = {
Expand Down

0 comments on commit c27d851

Please sign in to comment.