From 18d262c1ae6ca11153c910553ca695693ddd1191 Mon Sep 17 00:00:00 2001 From: Brad Humphrey Date: Tue, 28 Dec 2021 11:57:48 -0700 Subject: [PATCH] Add test for minimal accessibility --- Fill.py | 8 ++-- test/base/TestFill.py | 85 ++++++++++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 25 deletions(-) diff --git a/Fill.py b/Fill.py index f19cf0fd..0300b221 100644 --- a/Fill.py +++ b/Fill.py @@ -62,7 +62,7 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations, # try swaping this item with previously placed items for(i, location) in enumerate(placements): placed_item = location.item - # Unplaceable items can sometimes be swapped infinitely. Limit the + # Unplaceable items can sometimes be swapped infinitely. Limit the # number of times we will swap an individual item to prevent this if swapped_items[placed_item.player, placed_item.name] > 0: continue @@ -74,8 +74,10 @@ def fill_restrictive(world: MultiWorld, base_state: CollectionState, locations, # Add this item to the exisiting placement, and # add the old item to the back of the queue spot_to_fill = placements.pop(i) - swapped_items[placed_item.player, placed_item.name] += 1 - reachable_items[placed_item.player].appendleft(placed_item) + swapped_items[placed_item.player, + placed_item.name] += 1 + reachable_items[placed_item.player].appendleft( + placed_item) itempool.append(placed_item) break else: diff --git a/test/base/TestFill.py b/test/base/TestFill.py index 259cc8e4..e350e68a 100644 --- a/test/base/TestFill.py +++ b/test/base/TestFill.py @@ -84,20 +84,38 @@ class TestBase(unittest.TestCase): def test_ordered_fill_restrictive(self): multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) - - item0 = player1.prog_items[0] - item1 = player1.prog_items[1] - loc0 = player1.locations[0] - loc1 = player1.locations[1] + items = player1.prog_items + locations = player1.locations multi_world.completion_condition[player1.id] = lambda state: state.has( - item0.name, player1.id) and state.has(item1.name, player1.id) - set_rule(loc1, lambda state: state.has(item0.name, player1.id)) + items[0].name, player1.id) and state.has(items[1].name, player1.id) + set_rule(locations[1], lambda state: state.has( + items[0].name, player1.id)) fill_restrictive(multi_world, multi_world.state, - player1.locations, player1.prog_items) + player1.locations.copy(), player1.prog_items.copy()) - self.assertEqual(loc0.item, item0) - self.assertEqual(loc1.item, item1) + self.assertEqual(locations[0].item, items[0]) + self.assertEqual(locations[1].item, items[1]) + + def test_minimal_fill_restrictive(self): + multi_world = generate_multi_world() + player1 = generate_player_data(multi_world, 1, 2, 2) + + items = player1.prog_items + locations = player1.locations + + multi_world.accessibility[player1.id] = 'minimal' + multi_world.completion_condition[player1.id] = lambda state: state.has( + items[1].name, player1.id) + set_rule(locations[1], lambda state: state.has( + items[0].name, player1.id)) + + fill_restrictive(multi_world, multi_world.state, + player1.locations.copy(), player1.prog_items.copy()) + + self.assertEqual(locations[0].item, items[1]) + # Unnecessary unreachable Item + self.assertEqual(locations[1].item, items[0]) def test_reversed_fill_restrictive(self): multi_world = generate_multi_world() @@ -126,9 +144,12 @@ class TestBase(unittest.TestCase): multi_world.completion_condition[player1.id] = lambda state: state.has( items[2].name, player1.id) and state.has(items[3].name, player1.id) - set_rule(locations[1], lambda state: state.has(items[0].name, player1.id)) - set_rule(locations[2], lambda state: state.has(items[1].name, player1.id)) - set_rule(locations[3], lambda state: state.has(items[1].name, player1.id)) + set_rule(locations[1], lambda state: state.has( + items[0].name, player1.id)) + set_rule(locations[2], lambda state: state.has( + items[1].name, player1.id)) + set_rule(locations[3], lambda state: state.has( + items[1].name, player1.id)) fill_restrictive(multi_world, multi_world.state, player1.locations.copy(), player1.prog_items.copy()) @@ -138,22 +159,42 @@ class TestBase(unittest.TestCase): self.assertEqual(locations[2].item, items[0]) self.assertEqual(locations[3].item, items[3]) - def test_impossible_fill_restrictive(self): + def test_minimal_fill_restrictive(self): multi_world = generate_multi_world() player1 = generate_player_data(multi_world, 1, 2, 2) - item0 = player1.prog_items[0] - item1 = player1.prog_items[1] - loc0 = player1.locations[0] - loc1 = player1.locations[1] + items = player1.prog_items + locations = player1.locations + + multi_world.accessibility[player1.id] = 'minimal' + multi_world.completion_condition[player1.id] = lambda state: state.has( + items[1].name, player1.id) + set_rule(locations[1], lambda state: state.has( + items[0].name, player1.id)) + + fill_restrictive(multi_world, multi_world.state, + player1.locations.copy(), player1.prog_items.copy()) + + self.assertEqual(locations[0].item, items[1]) + # Unnecessary unreachable Item + self.assertEqual(locations[1].item, items[0]) + + def test_impossible_fill_restrictive(self): + multi_world = generate_multi_world() + player1 = generate_player_data(multi_world, 1, 2, 2) + items = player1.prog_items + locations = player1.locations multi_world.completion_condition[player1.id] = lambda state: state.has( - item0.name, player1.id) and state.has(item1.name, player1.id) - set_rule(loc1, lambda state: state.has(item1.name, player1.id)) - set_rule(loc0, lambda state: state.has(item0.name, player1.id)) + items[0].name, player1.id) and state.has(items[1].name, player1.id) + set_rule(locations[1], lambda state: state.has( + items[1].name, player1.id)) + set_rule(locations[0], lambda state: state.has( + items[0].name, player1.id)) + with pytest.raises(FillError): fill_restrictive(multi_world, multi_world.state, - player1.locations, player1.prog_items) + player1.locations.copy(), player1.prog_items.copy()) def test_circular_fill_restrictive(self): multi_world = generate_multi_world()