From 6d93a6234e80463b72dec7103a329764456aee2e Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Sat, 29 Jul 2023 19:44:10 +0200 Subject: [PATCH] MultiServer: fix wrong missing for empty state w/o speedups and add/fix tests (#2052) * MultiServer: fix wrong missing for empty state w/o speedups * Tests: fix some tests not being run * Tests: add test for set intersection with LocationStore --- NetUtils.py | 2 +- test/netutils/TestLocationStore.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NetUtils.py b/NetUtils.py index 99c37238..c31aa695 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -390,7 +390,7 @@ class _LocationStore(dict, typing.MutableMapping[int, typing.Dict[int, typing.Tu checked = state[team, slot] if not checked: # This optimizes the case where everyone connects to a fresh game at the same time. - return list(self) + return list(self[slot]) return [location_id for location_id in self[slot] if location_id not in checked] diff --git a/test/netutils/TestLocationStore.py b/test/netutils/TestLocationStore.py index 9fe904f6..a7f11725 100644 --- a/test/netutils/TestLocationStore.py +++ b/test/netutils/TestLocationStore.py @@ -97,24 +97,29 @@ class Base: self.assertEqual(self.store.get_for_player(3), {4: {9}}) self.assertEqual(self.store.get_for_player(1), {1: {13}, 2: {22, 23}}) - def get_checked(self) -> None: + def test_get_checked(self) -> None: self.assertEqual(self.store.get_checked(full_state, 0, 1), [11, 12, 13]) self.assertEqual(self.store.get_checked(one_state, 0, 1), [12]) self.assertEqual(self.store.get_checked(empty_state, 0, 1), []) self.assertEqual(self.store.get_checked(full_state, 0, 3), [9]) - def get_missing(self) -> None: + def test_get_missing(self) -> None: self.assertEqual(self.store.get_missing(full_state, 0, 1), []) self.assertEqual(self.store.get_missing(one_state, 0, 1), [11, 13]) self.assertEqual(self.store.get_missing(empty_state, 0, 1), [11, 12, 13]) self.assertEqual(self.store.get_missing(empty_state, 0, 3), [9]) - def get_remaining(self) -> None: + def test_get_remaining(self) -> None: self.assertEqual(self.store.get_remaining(full_state, 0, 1), []) self.assertEqual(self.store.get_remaining(one_state, 0, 1), [13, 21]) self.assertEqual(self.store.get_remaining(empty_state, 0, 1), [13, 21, 22]) self.assertEqual(self.store.get_remaining(empty_state, 0, 3), [99]) + def test_location_set_intersection(self) -> None: + locations = {10, 11, 12} + locations.intersection_update(self.store[1]) + self.assertEqual(locations, {11, 12}) + class TestLocationStoreConstructor(unittest.TestCase): """Test constructors for a given store type.""" type: type