Skip to content

[small] Feature/add tests#10

Merged
RobbieKiwi merged 10 commits into
mainfrom
feature/add-tests
Jun 9, 2025
Merged

[small] Feature/add tests#10
RobbieKiwi merged 10 commits into
mainfrom
feature/add-tests

Conversation

@RobbieKiwi

@RobbieKiwi RobbieKiwi commented Jun 6, 2025

Copy link
Copy Markdown
Owner
  • Added some tools for generating objects for testing
  • Added some tests of some core models

@RobbieKiwi RobbieKiwi requested a review from RomanCantu June 6, 2025 17:22
Comment thread tests/utils/repo_maker.py
def __init__(self, player_ids: Optional[list[PlayerId]] = None) -> None:
super().__init__()
if player_ids is None:
player_ids = [PlayerId(i) for i in range(3)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if these repo makers are to be used for anything other than tests (e.g., create a new game), maybe we don't want the player counter to start at zero?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is not to use them for anything other than tests. Why would we not want to start at 0? The player number will never be displayed to the player it is just for the back end. The player will see their name

Comment thread tests/utils/repo_maker.py Outdated
def make_quick(
cls, n_normal_assets: int = 3, player_ids: Optional[list[PlayerId]] = None, bus_repo: Optional[BusRepo] = None
) -> AssetRepo:
return cls(player_ids=player_ids, bus_repo=bus_repo).add_n_random(n_normal_assets).make()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are normal assets?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normal assets are not ice cream buses

Comment thread tests/utils/repo_maker.py Outdated
return self

def _get_random_player_id(self) -> PlayerId:
return safe_random_choice(self.player_ids) if safe_random_choice([True, False]) else PlayerId.get_npc()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method seems overcomplicated and gives preference to the npc. Why not just appending the npc id to the player_ids?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to generate 10 random assets, then probably half of them will belong to the npc

Comment thread tests/utils/repo_maker.py Outdated
return AssetRepo

def _pre_make_hook(self) -> None:
ice_cream_buses = [bus for bus in self._bus_repo if bus.is_ice_cream_bus]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finding ice cream buses could be a method in BusRepo

Comment thread tests/utils/repo_maker.py
self.player_ids = player_ids
self.bus_ids = bus_ids

def _get_random_player_id(self) -> PlayerId:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as before (overcomplicated method and gives preference to npc), and can we somehow avoid this duplicated code?

Comment thread tests/utils/repo_maker.py
def _pre_make_hook(self) -> None:
# Connect islands before making the repo
mentioned_buses = {t.bus1 for t in self.dcs} | {t.bus2 for t in self.dcs}
islanded_buses = [bus for bus in self.bus_ids if bus not in mentioned_buses]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another good method to include in BusRepo: islanded buses

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That cannot be in the bus repo because then the bus repo would have to know about the transmsision repo

Comment thread tests/test_models/test_player.py Outdated
from tests.utils.repo_maker import AssetRepoMaker, BusRepoMaker


class TestPlayers(TestCase):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are testing more than just the players, right? check the class name

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems you copied the methods from test_assets.py and forgot to delete them after

Comment thread src/models/transmission.py Outdated

def __post_init__(self) -> None:
assert self.bus2 > self.bus1
assert self.bus2 > self.bus1, f"bus2 must be greater than bus2. Got {self.bus2} and {self.bus1}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the string has a typo, bus2 is repeated

@RobbieKiwi RobbieKiwi merged commit 55a3c0e into main Jun 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants