M2: set17.toml game constants + validating loader
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
42
backend/tests/test_constants.py
Normal file
42
backend/tests/test_constants.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import pytest
|
||||
|
||||
from tft.constants.loader import load_constants, validate
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def c():
|
||||
return load_constants(17)
|
||||
|
||||
|
||||
def test_loads_and_validates(c):
|
||||
assert c["set"] == 17
|
||||
|
||||
|
||||
def test_shop_odds_shape(c):
|
||||
assert len(c["shop"]["odds"]) == c["xp"]["max_level"]
|
||||
for row in c["shop"]["odds"]:
|
||||
assert sum(row) == 100
|
||||
|
||||
|
||||
def test_xp_reaches_max_level(c):
|
||||
assert len(c["xp"]["to_next"]) == c["xp"]["max_level"] - 1
|
||||
assert all(x > 0 for x in c["xp"]["to_next"])
|
||||
|
||||
|
||||
def test_interest_and_streaks(c):
|
||||
g = c["gold"]
|
||||
assert g["interest_cap"] >= 1
|
||||
streaks = g["streak_gold"]
|
||||
assert streaks == sorted(streaks)
|
||||
assert all(gold > 0 for _, gold in streaks)
|
||||
|
||||
|
||||
def test_missing_set_raises():
|
||||
with pytest.raises(FileNotFoundError):
|
||||
load_constants(99)
|
||||
|
||||
|
||||
def test_validation_catches_bad_odds(c):
|
||||
c["shop"]["odds"][0] = [99, 0, 0, 0, 0]
|
||||
with pytest.raises(ValueError, match="sum to 99"):
|
||||
validate(c)
|
||||
Reference in New Issue
Block a user