test(game-engine): Add integration tests for happiness mechanics, including turn progression and threshold validation

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-04-16 11:29:47 -07:00
parent cb899d1ab4
commit fe8abea5eb

View file

@ -316,3 +316,29 @@ func test_save_load_preserves_breakdown_and_status() -> void:
"breakdown.status must survive round-trip")
assert_eq(int(bd.get("city_unhappiness", 0)), 3,
"breakdown.city_unhappiness must survive round-trip")
func test_luxury_count_adds_happiness_via_rust() -> void:
## Task #6 target A: each unique luxury resource adds LUXURY_HAPPINESS (+4)
## to the breakdown. Mirrors mc-happiness pool.rs LUXURY_HAPPINESS constant.
## Drives Rust `GdHappiness.calculate` directly with varying luxury counts so
## the test does not depend on GameMap/Tile setup for owned_tiles traversal.
if not ClassDB.class_exists("GdHappiness"):
pass_test("GdHappiness extension not loaded in this test run")
return
var gd: RefCounted = ClassDB.instantiate("GdHappiness") as RefCounted
var base_input: Dictionary = {
"city_count": 1, "total_citizens": 3,
"units_in_enemy_territory": 0, "ascension_active": false,
"building_happiness": 0, "unique_luxury_count": 0,
"growth_tier": "balanced",
}
var zero: Dictionary = gd.call("calculate", JSON.stringify(base_input))
base_input["unique_luxury_count"] = 2
var two: Dictionary = gd.call("calculate", JSON.stringify(base_input))
assert_eq(int(zero.get("luxury_happiness", 0)), 0,
"zero luxuries must yield 0 luxury_happiness")
assert_eq(int(two.get("luxury_happiness", 0)), 8,
"two luxuries must yield +8 luxury_happiness (2 * LUXURY_HAPPINESS=4)")
assert_eq(int(two.get("total", 0)) - int(zero.get("total", 0)), 8,
"total delta for +2 luxuries must be +8")