extends "res://addons/gut/test.gd"

const Luck = preload("res://scripts/state/luck.gd")


func _rng(s: int) -> RandomNumberGenerator:
	var r := RandomNumberGenerator.new()
	r.seed = s
	return r


func test_roll_base_is_deterministic_for_a_seed():
	assert_eq(Luck.roll_base(_rng(42), 0), Luck.roll_base(_rng(42), 0))


func test_roll_base_stays_in_range():
	for s in range(1, 30):
		var v := Luck.roll_base(_rng(s), 0)
		assert_true(v >= Luck.MIN and v <= Luck.MAX, "luck %d out of range" % v)


func test_modifier_shifts_result():
	# +100 modifier clamps to MAX regardless of rolls.
	assert_eq(Luck.roll_base(_rng(5), 100), Luck.MAX)


func test_drift_stays_within_base_band_and_range():
	assert_eq(Luck.drift(10, 10, 100), 13)   # capped at base+3
	assert_eq(Luck.drift(10, 10, -100), 7)    # capped at base-3
	assert_eq(Luck.drift(20, 19, 100), 20)    # base+3=22 -> clamped to MAX


func test_descriptor_bands():
	assert_eq(Luck.descriptor(4), "Fortune spits on you")
	assert_eq(Luck.descriptor(5), "The world is not on your side")
	assert_eq(Luck.descriptor(20), "The dice are kind today")
