Skip to content

Commit

Permalink
Add some tests for items. Adjust options for upgrades per unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziktofel committed Jun 7, 2024
1 parent 4055cc9 commit 636aa13
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion worlds/sc2/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class VanillaItemsOnly(Toggle):


# Current maximum number of upgrades for a unit
MAX_UPGRADES_OPTION = 12
MAX_UPGRADES_OPTION = 14


class EnsureGenericItems(Range):
Expand Down
57 changes: 57 additions & 0 deletions worlds/sc2/test/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,60 @@ def test_number_distinct_in_item_type(self) -> None:
item_numbers: Set[int] = {items.get_full_item_list()[item_name] for item_name in item_names}

self.assertEqual(len(item_names), len(item_numbers))

def test_progressive_has_quantity(self) -> None:
progressive_groups: List[items.ItemTypeEnum] = [
items.TerranItemType.Progressive,
items.TerranItemType.Progressive_2,
items.ProtossItemType.Progressive
]

quantities: List[int] = [
items.get_full_item_list()[item].quantity for item in items.get_full_item_list()
if items.get_full_item_list()[item].type in progressive_groups
]

self.assertNotIn(1, quantities)

def test_non_progressive_quantity(self) -> None:
non_progressive_single_entity_groups: List[items.ItemTypeEnum] = [
# Terran
items.TerranItemType.Unit,
items.TerranItemType.Mercenary,
items.TerranItemType.Armory_1,
items.TerranItemType.Armory_2,
items.TerranItemType.Armory_3,
items.TerranItemType.Armory_4,
items.TerranItemType.Armory_5,
items.TerranItemType.Armory_6,
items.TerranItemType.Building,
items.TerranItemType.Laboratory,
items.TerranItemType.Nova_Gear,
# Zerg
items.ZergItemType.Unit,
items.ZergItemType.Mercenary,
items.ZergItemType.Morph,
items.ZergItemType.Strain,
items.ZergItemType.Mutation_1,
items.ZergItemType.Mutation_2,
items.ZergItemType.Mutation_3,
items.ZergItemType.Evolution_Pit,
items.ZergItemType.Ability,
# Protoss
items.ProtossItemType.Unit,
items.ProtossItemType.Unit_2,
items.ProtossItemType.Building,
items.ProtossItemType.Forge_1,
items.ProtossItemType.Forge_2,
items.ProtossItemType.Forge_3,
items.ProtossItemType.Solarite_Core,
items.ProtossItemType.Spear_Of_Adun
]

quantities: List[int] = [
items.get_full_item_list()[item].quantity for item in items.get_full_item_list()
if items.get_full_item_list()[item].type in non_progressive_single_entity_groups
]

for quantity in quantities:
self.assertLessEqual(quantity, 1)
25 changes: 23 additions & 2 deletions worlds/sc2/test/test_options.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import unittest
from typing import Set, Dict, List

from .test_base import Sc2TestBase
from .. import mission_tables, options
from .. import mission_tables, options, items


class TestOptions(unittest.TestCase):
def test_campaign_size_option_max_matches_number_of_missions(self):
def test_campaign_size_option_max_matches_number_of_missions(self) -> None:
self.assertEqual(options.MaximumCampaignSize.range_end, len(mission_tables.SC2Mission))

def test_unit_max_upgrades_matching_items(self) -> None:
base_items: Set[str] = {
items.get_full_item_list()[item].parent_item for item in items.get_full_item_list()
if items.get_full_item_list()[item].parent_item is not None
}

upgrade_items: Dict[str, List[str]] = dict()
for item in base_items:
upgrade_items[item] = [
upgrade_item for upgrade_item in items.get_full_item_list()
if items.get_full_item_list()[upgrade_item].parent_item == item
]
upgrade_counter: List[int] = list()
for item in base_items:
quantities: List[int] = [items.get_full_item_list()[upgrade_item].quantity for upgrade_item in upgrade_items[item]]
upgrade_counter.append(sum(quantities))

self.assertEqual(options.MAX_UPGRADES_OPTION, max(upgrade_counter))

0 comments on commit 636aa13

Please sign in to comment.