Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions tests/classic/test_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import pytest

from codenames.classic.color import CARD_COLOR_TO_EMOJI, ClassicColor


def test_classic_color_values():
"""Test that all expected colors are defined."""
assert ClassicColor.BLUE.value == "BLUE"
assert ClassicColor.RED.value == "RED"
assert ClassicColor.NEUTRAL.value == "NEUTRAL"
assert ClassicColor.ASSASSIN.value == "ASSASSIN"


def test_classic_color_emoji_blue():
"""Test emoji property for blue color."""
assert ClassicColor.BLUE.emoji == "🟦"


def test_classic_color_emoji_red():
"""Test emoji property for red color."""
assert ClassicColor.RED.emoji == "🟥"


def test_classic_color_emoji_neutral():
"""Test emoji property for neutral color."""
assert ClassicColor.NEUTRAL.emoji == "⬜"


def test_classic_color_emoji_assassin():
"""Test emoji property for assassin color."""
assert ClassicColor.ASSASSIN.emoji == "💀"


def test_all_colors_have_emoji_mapping():
"""Test that all colors have corresponding emoji in the mapping."""
for color in ClassicColor:
assert color in CARD_COLOR_TO_EMOJI
assert isinstance(CARD_COLOR_TO_EMOJI[color], str)
assert len(CARD_COLOR_TO_EMOJI[color]) > 0


def test_emoji_mapping_contains_only_valid_colors():
"""Test that emoji mapping doesn't contain extra keys."""
assert len(CARD_COLOR_TO_EMOJI) == 4
assert set(CARD_COLOR_TO_EMOJI.keys()) == {
ClassicColor.RED,
ClassicColor.BLUE,
ClassicColor.NEUTRAL,
ClassicColor.ASSASSIN,
}


def test_color_string_representation():
"""Test string representation of colors."""
assert str(ClassicColor.BLUE) == "ClassicColor.BLUE"
assert str(ClassicColor.RED) == "ClassicColor.RED"


def test_color_equality():
"""Test that color instances are equal to themselves."""
assert ClassicColor.BLUE == ClassicColor.BLUE
assert ClassicColor.RED != ClassicColor.BLUE


def test_color_iteration():
"""Test that we can iterate over all colors."""
colors = list(ClassicColor)
assert len(colors) == 4
assert ClassicColor.BLUE in colors
assert ClassicColor.RED in colors
assert ClassicColor.NEUTRAL in colors
assert ClassicColor.ASSASSIN in colors


def test_color_membership():
"""Test membership checks for color enum."""
assert "BLUE" in ClassicColor.__members__
assert "RED" in ClassicColor.__members__
assert "NEUTRAL" in ClassicColor.__members__
assert "ASSASSIN" in ClassicColor.__members__
assert "INVALID" not in ClassicColor.__members__
142 changes: 142 additions & 0 deletions tests/classic/test_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import pytest

from codenames.classic.color import ClassicColor
from codenames.classic.team import ClassicTeam


def test_classic_team_values():
"""Test that all expected teams are defined."""
assert ClassicTeam.BLUE.value == "BLUE"
assert ClassicTeam.RED.value == "RED"


def test_classic_team_as_card_color_blue():
"""Test as_card_color for blue team."""
assert ClassicTeam.BLUE.as_card_color == ClassicColor.BLUE


def test_classic_team_as_card_color_red():
"""Test as_card_color for red team."""
assert ClassicTeam.RED.as_card_color == ClassicColor.RED


def test_classic_team_opponent_blue():
"""Test opponent property for blue team."""
assert ClassicTeam.BLUE.opponent == ClassicTeam.RED


def test_classic_team_opponent_red():
"""Test opponent property for red team."""
assert ClassicTeam.RED.opponent == ClassicTeam.BLUE


def test_classic_team_double_opponent():
"""Test that opponent of opponent returns original team."""
assert ClassicTeam.BLUE.opponent.opponent == ClassicTeam.BLUE
assert ClassicTeam.RED.opponent.opponent == ClassicTeam.RED


def test_classic_team_string_representation():
"""Test string representation of teams."""
assert str(ClassicTeam.BLUE) == "ClassicTeam.BLUE"
assert str(ClassicTeam.RED) == "ClassicTeam.RED"


def test_classic_team_equality():
"""Test that team instances are equal to themselves."""
assert ClassicTeam.BLUE == ClassicTeam.BLUE
assert ClassicTeam.RED == ClassicTeam.RED
assert ClassicTeam.BLUE != ClassicTeam.RED


def test_classic_team_iteration():
"""Test that we can iterate over all teams."""
teams = list(ClassicTeam)
assert len(teams) == 2
assert ClassicTeam.BLUE in teams
assert ClassicTeam.RED in teams


def test_classic_team_membership():
"""Test membership checks for team enum."""
assert "BLUE" in ClassicTeam.__members__
assert "RED" in ClassicTeam.__members__
assert "GREEN" not in ClassicTeam.__members__


def test_classic_team_card_color_types():
"""Test that as_card_color returns ClassicColor instances."""
assert isinstance(ClassicTeam.BLUE.as_card_color, ClassicColor)
assert isinstance(ClassicTeam.RED.as_card_color, ClassicColor)


def test_classic_team_opponent_types():
"""Test that opponent returns ClassicTeam instances."""
assert isinstance(ClassicTeam.BLUE.opponent, ClassicTeam)
assert isinstance(ClassicTeam.RED.opponent, ClassicTeam)


def test_classic_team_all_teams_have_card_color():
"""Test that all teams have a corresponding card color."""
for team in ClassicTeam:
card_color = team.as_card_color
assert card_color is not None
assert isinstance(card_color, ClassicColor)


def test_classic_team_all_teams_have_opponent():
"""Test that all teams have an opponent."""
for team in ClassicTeam:
opponent = team.opponent
assert opponent is not None
assert isinstance(opponent, ClassicTeam)
assert opponent != team


def test_classic_team_card_color_matches_team_name():
"""Test that card color matches team name."""
assert ClassicTeam.BLUE.as_card_color == ClassicColor.BLUE
assert ClassicTeam.RED.as_card_color == ClassicColor.RED


def test_classic_team_opponents_are_symmetric():
"""Test that if A's opponent is B, then B's opponent is A."""
blue_opponent = ClassicTeam.BLUE.opponent
red_opponent = ClassicTeam.RED.opponent

assert blue_opponent == ClassicTeam.RED
assert red_opponent == ClassicTeam.BLUE


def test_classic_team_can_be_used_in_set():
"""Test that teams can be used in sets."""
team_set = {ClassicTeam.BLUE, ClassicTeam.RED, ClassicTeam.BLUE}
assert len(team_set) == 2


def test_classic_team_can_be_used_as_dict_key():
"""Test that teams can be used as dictionary keys."""
team_dict = {
ClassicTeam.BLUE: "Blue Team",
ClassicTeam.RED: "Red Team",
}
assert team_dict[ClassicTeam.BLUE] == "Blue Team"
assert team_dict[ClassicTeam.RED] == "Red Team"


def test_classic_team_hashable():
"""Test that teams are hashable."""
blue_hash = hash(ClassicTeam.BLUE)
red_hash = hash(ClassicTeam.RED)

assert isinstance(blue_hash, int)
assert isinstance(red_hash, int)
assert blue_hash != red_hash


def test_classic_team_comparison():
"""Test team comparison operations."""
assert ClassicTeam.BLUE == ClassicTeam.BLUE
assert not (ClassicTeam.BLUE != ClassicTeam.BLUE)
assert ClassicTeam.BLUE != ClassicTeam.RED
assert not (ClassicTeam.BLUE == ClassicTeam.RED)
Loading
Loading