extends TestCase ## The balance pass's report (H3): match length quantiles, weapon shares, survivors ## over time, and the verdict against the BALANCE_* targets. func _match(seed_value: int, minutes: float, kills: Dictionary, winner: String = "normal") -> Dictionary: var deaths: Array = [] for index: int in Tuning.SOLO_PLAYERS - 1: deaths.append(minutes * 60.0 * (index + 1) / Tuning.SOLO_PLAYERS) return { "seed": seed_value, "finished": true, "winner": -1, "winner_difficulty": winner, "timed_out": false, "causes": {"weapon": Tuning.SOLO_PLAYERS - 1}, "places": {"normal": [1, 2]}, "eliminations": {"normal": 2}, "weapon_kills": kills, "death_seconds": deaths, "shots": 10, "ticks": roundi(minutes * 60.0 * Tuning.TICK_RATE_HZ), "timing": {"p99_us": 100, "over_budget": 0}, "state_hash": "x", } func test_quantiles_interpolate() -> void: var values: Array[float] = [1.0, 2.0, 3.0, 4.0] assert_eq(BalanceReport.quantile(values, 0.0), 1.0) assert_eq(BalanceReport.quantile(values, 0.5), 2.5) assert_eq(BalanceReport.quantile(values, 1.0), 4.0) assert_eq(BalanceReport.quantile([] as Array[float], 0.5), 0.0) func test_a_balanced_batch_passes() -> void: var results: Array[Dictionary] = [] for index: int in Tuning.BALANCE_MIN_MATCHES: results.append(_match(index, 13.0 + (index % 5) * 0.5, {"dock_carbine": 8, "signal_revolver": 8, "rivet_repeater": 7})) var a: Dictionary = BalanceReport.analyse(results) assert_eq(a["problems"], [], "no problems: %s" % [a["problems"]]) assert_eq(a["minutes"]["median"], 14.0) assert_true(absf(a["weapon_share"]["dock_carbine"] - 8.0 / 23.0) < 0.001) assert_true(a["standing"][12] > 1.0 and a["standing"][2] > a["standing"][12], "survivors fall over time: %s" % [a["standing"]]) assert_true(BalanceReport.format(a).contains("balance: ok")) func test_short_matches_a_dominant_weapon_and_a_small_batch_fail() -> void: var results: Array[Dictionary] = [] for index: int in 10: results.append(_match(index, 6.0, {"rivet_repeater": 20, "dock_carbine": 3})) var a: Dictionary = BalanceReport.analyse(results) var text: String = BalanceReport.format(a) assert_eq(a["problems"].size(), 3, "count, length and weapon: %s" % [a["problems"]]) assert_true(text.contains("only 10 matches")) assert_true(text.contains("median match length 6.0 min")) assert_true(text.contains("rivet_repeater took 87%")) func test_every_match_ends_inside_the_longest_target() -> void: var seconds: float = float(Tide.new(0).time_limit_offset()) / Tuning.TICK_RATE_HZ assert_true(seconds <= Tuning.BALANCE_MEDIAN_MINUTES_MAX * 60.0, "the tide and sudden death take %.0f s" % seconds) assert_true(seconds >= Tuning.BALANCE_MEDIAN_MINUTES_MIN * 60.0, "and leave room for a %.0f-minute match" % Tuning.BALANCE_MEDIAN_MINUTES_MIN)