Skip to content

Commit 17fb4cc

Browse files
authored
feat!: Replace assert with ValueError for tile count validation in Shanten.calculate_shanten_for_regular_hand() (#184)
1 parent 62e8fe4 commit 17fb4cc

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The following methods are now available as static methods:
9292
- Yaku calculation order has changed: chinitsu/honitsu are now mutually exclusive, and tsuisou/honroto/chinroto checks now require no chi sets. Users manually overwriting `config.yaku` fields may be affected.
9393
- Yakuhai detection (hatsu, haku, chun, winds) now uses `has_pon_or_kan_of()` instead of counting triplets. Behavior changes for invalid hands with two or more identical triplets of the same tile.
9494
- Fixed an issue where `KokushiMusou.is_condition_met()` would return `None` if the condition was not met. It now consistently returns a `bool` value. Remove any `None` checks in the code that relied on the previous behavior.
95+
- `Shanten.calculate_shanten()` and `Shanten.calculate_shanten_for_regular_hand()` now raises `ValueError` instead of `assert` when the number of tiles is 15 or more.
9596

9697
## What's Changed
9798
- Placeholder. It would be filled on release automatically

mahjong/shanten.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def __init__(self, tiles_34: Sequence[int]) -> None:
6969

7070
def calculate(self) -> int:
7171
count_of_tiles = sum(self._tiles)
72-
assert count_of_tiles <= 14, f"Too many tiles = {count_of_tiles}"
72+
if count_of_tiles > 14:
73+
msg = f"Too many tiles = {count_of_tiles}"
74+
raise ValueError(msg)
7375

7476
self._remove_character_tiles(count_of_tiles)
7577

tests/tests_shanten.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def test_calculate_shanten(sou: str, pin: str, man: str, honors: str, shanten_nu
1919
assert shanten.calculate_shanten(tiles) == shanten_number
2020

2121

22+
def test_calculate_shanten_raises_error_too_many_tiles() -> None:
23+
tiles = TilesConverter.string_to_34_array(sou="1111", pin="1111", man="1111", honors="111")
24+
with pytest.raises(ValueError, match="Too many tiles = 15"):
25+
Shanten.calculate_shanten(tiles)
26+
27+
2228
@pytest.mark.parametrize(
2329
("sou", "pin", "man", "honors", "shanten_number"),
2430
[

0 commit comments

Comments
 (0)