| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  | import unittest | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from BaseClasses import CollectionState | 
					
						
							|  |  |  | from worlds.AutoWorld import AutoWorldRegister | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  | from . import setup_solo_multiworld | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 03:32:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  | class TestBase(unittest.TestCase): | 
					
						
							|  |  |  |     gen_steps = ["generate_early", "create_regions", "create_items", "set_rules", "generate_basic", "pre_fill"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-19 23:09:54 +01:00
										 |  |  |     default_settings_unreachable_regions = { | 
					
						
							|  |  |  |         "A Link to the Past": { | 
					
						
							|  |  |  |             "Chris Houlihan Room",  # glitch room by definition | 
					
						
							|  |  |  |             "Desert Northern Cliffs",  # on top of mountain, only reachable via OWG | 
					
						
							|  |  |  |             "Dark Death Mountain Bunny Descent Area"  # OWG Mountain descent | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         "Ocarina of Time": { | 
					
						
							|  |  |  |             "Prelude of Light Warp",  # Prelude is not progression by default | 
					
						
							|  |  |  |             "Serenade of Water Warp",  # Serenade is not progression by default | 
					
						
							|  |  |  |             "Lost Woods Mushroom Timeout",  # trade quest starts after this item | 
					
						
							|  |  |  |             "ZD Eyeball Frog Timeout",  # trade quest starts after this item | 
					
						
							|  |  |  |             "ZR Top of Waterfall",  # dummy region used for entrance shuffle | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         # The following SM regions are only used when the corresponding StartLocation option is selected (so not with default settings). | 
					
						
							|  |  |  |         # Also, those dont have any entrances as they serve as starting Region (that's why they have to be excluded for testAllStateCanReachEverything). | 
					
						
							|  |  |  |         "Super Metroid": { | 
					
						
							|  |  |  |             "Ceres", | 
					
						
							|  |  |  |             "Gauntlet Top", | 
					
						
							|  |  |  |             "Mama Turtle" | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  |     def testAllStateCanReachEverything(self): | 
					
						
							|  |  |  |         for game_name, world_type in AutoWorldRegister.world_types.items(): | 
					
						
							| 
									
										
										
										
											2022-02-20 14:19:20 -07:00
										 |  |  |             # Final Fantasy logic is controlled by finalfantasyrandomizer.com | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  |             if game_name not in {"Ori and the Blind Forest"}:  # TODO: fix Ori Logic | 
					
						
							| 
									
										
										
										
											2023-02-19 23:09:54 +01:00
										 |  |  |                 unreachable_regions = self.default_settings_unreachable_regions.get(game_name, set()) | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  |                 with self.subTest("Game", game=game_name): | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  |                     world = setup_solo_multiworld(world_type) | 
					
						
							| 
									
										
										
										
											2022-04-01 03:32:17 +02:00
										 |  |  |                     excluded = world.exclude_locations[1].value | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  |                     state = world.get_all_state(False) | 
					
						
							|  |  |  |                     for location in world.get_locations(): | 
					
						
							| 
									
										
										
										
											2022-04-01 03:32:17 +02:00
										 |  |  |                         if location.name not in excluded: | 
					
						
							|  |  |  |                             with self.subTest("Location should be reached", location=location): | 
					
						
							| 
									
										
										
										
											2022-09-28 14:54:10 -07:00
										 |  |  |                                 self.assertTrue(location.can_reach(state), f"{location.name} unreachable") | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-19 23:09:54 +01:00
										 |  |  |                     for region in world.get_regions(): | 
					
						
							|  |  |  |                         if region.name not in unreachable_regions: | 
					
						
							|  |  |  |                             with self.subTest("Region should be reached", region=region): | 
					
						
							|  |  |  |                                 self.assertTrue(region.can_reach(state)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-10 19:48:54 +02:00
										 |  |  |                     with self.subTest("Completion Condition"): | 
					
						
							|  |  |  |                         self.assertTrue(world.can_beat_game(state)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  |     def testEmptyStateCanReachSomething(self): | 
					
						
							|  |  |  |         for game_name, world_type in AutoWorldRegister.world_types.items(): | 
					
						
							| 
									
										
										
										
											2022-02-20 14:19:20 -07:00
										 |  |  |             # Final Fantasy logic is controlled by finalfantasyrandomizer.com | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  |             if game_name not in {"Archipelago", "Sudoku"}: | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  |                 with self.subTest("Game", game=game_name): | 
					
						
							| 
									
										
										
										
											2023-02-15 15:46:10 -06:00
										 |  |  |                     world = setup_solo_multiworld(world_type) | 
					
						
							| 
									
										
										
										
											2021-10-21 20:23:13 +02:00
										 |  |  |                     state = CollectionState(world) | 
					
						
							|  |  |  |                     locations = set() | 
					
						
							|  |  |  |                     for location in world.get_locations(): | 
					
						
							|  |  |  |                         if location.can_reach(state): | 
					
						
							|  |  |  |                             locations.add(location) | 
					
						
							|  |  |  |                     self.assertGreater(len(locations), 0, | 
					
						
							| 
									
										
										
										
											2022-02-20 14:19:20 -07:00
										 |  |  |                                        msg="Need to be able to reach at least one location to get started.") |