From e5af7d11cc84e8c98339bb6e8dea48240cefcba6 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 29 Jan 2022 16:10:42 +0100 Subject: [PATCH] Tests: add ID range checks --- test/general/TestIDs.py | 54 ++++++++++++++++++++++++++++++++++ test/general/TestUniqueness.py | 19 ------------ 2 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 test/general/TestIDs.py delete mode 100644 test/general/TestUniqueness.py diff --git a/test/general/TestIDs.py b/test/general/TestIDs.py new file mode 100644 index 00000000..05a90c0e --- /dev/null +++ b/test/general/TestIDs.py @@ -0,0 +1,54 @@ +import unittest +from worlds.AutoWorld import AutoWorldRegister + + +class TestIDs(unittest.TestCase): + def testUniqueItems(self): + known_item_ids = set() + for gamename, world_type in AutoWorldRegister.world_types.items(): + current = len(known_item_ids) + known_item_ids |= set(world_type.item_id_to_name) + self.assertEqual(len(known_item_ids) - len(world_type.item_id_to_name), current) + + def testUniqueLocations(self): + known_location_ids = set() + for gamename, world_type in AutoWorldRegister.world_types.items(): + current = len(known_location_ids) + known_location_ids |= set(world_type.location_id_to_name) + self.assertEqual(len(known_location_ids) - len(world_type.location_id_to_name), current) + + def testRangeItems(self): + """There are Javascript clients, which are limited to 2**53 integer size.""" + for gamename, world_type in AutoWorldRegister.world_types.items(): + with self.subTest(game=gamename): + for item_id in world_type.item_id_to_name: + self.assertLess(item_id, 2**53) + + def testRangeLocations(self): + """There are Javascript clients, which are limited to 2**53 integer size.""" + for gamename, world_type in AutoWorldRegister.world_types.items(): + with self.subTest(game=gamename): + for location_id in world_type.location_id_to_name: + self.assertLess(location_id, 2**53) + + def testReservedItems(self): + """negative IDs are reserved to the special "Archipelago" world.""" + for gamename, world_type in AutoWorldRegister.world_types.items(): + with self.subTest(game=gamename): + if gamename == "Archipelago": + for item_id in world_type.item_id_to_name: + self.assertLess(item_id, 0) + else: + for item_id in world_type.item_id_to_name: + self.assertGreater(item_id, 0) + + def testReservedLocations(self): + """negative IDs are reserved to the special "Archipelago" world.""" + for gamename, world_type in AutoWorldRegister.world_types.items(): + with self.subTest(game=gamename): + if gamename == "Archipelago": + for location_id in world_type.location_id_to_name: + self.assertLess(location_id, 0) + else: + for location_id in world_type.location_id_to_name: + self.assertGreater(location_id, 0) diff --git a/test/general/TestUniqueness.py b/test/general/TestUniqueness.py deleted file mode 100644 index f8ea8b26..00000000 --- a/test/general/TestUniqueness.py +++ /dev/null @@ -1,19 +0,0 @@ -import unittest -from worlds.AutoWorld import AutoWorldRegister - - -class TestBase(unittest.TestCase): - def testUniqueItems(self): - known_item_ids = set() - for gamename, world_type in AutoWorldRegister.world_types.items(): - current = len(known_item_ids) - known_item_ids |= set(world_type.item_id_to_name) - self.assertEqual(len(known_item_ids) - len(world_type.item_id_to_name), current) - - def testUniqueLocations(self): - known_location_ids = set() - for gamename, world_type in AutoWorldRegister.world_types.items(): - current = len(known_location_ids) - known_location_ids |= set(world_type.location_id_to_name) - self.assertEqual(len(known_location_ids) - len(world_type.location_id_to_name), current) -