Files
snake-python/tests/scripts/test_gameplay_snake_stats.py
T
daniel156161 5e121c20cf
Build and Push Docker Container / build-and-push (push) Successful in 3m6s
feat: add gameplay stats and restore Zenith rollout depth
- Add read-only gameplay statistics with filters and opponent comparisons.
- Report move-trace latency percentiles and external timeout counts.
- Pair engine latency with the preceding turn to separate timing stages.
- Adjust Zenith rollout deepening for its larger timeout reserve.
- Bump Zenith to 1.2.0 and document the fix and snake-stats command.
- Cover statistics, trace aggregation, rollout depth, and verdict budgets.
2026-11-05 08:07:15 +01:00

47 lines
1.7 KiB
Python

import unittest
from scripts.gameplay_snake_stats import (
StatsFilter, build_where, format_table, opponent_query, pivot_rows, win_rate,
)
class TestGameplaySnakeStats(unittest.TestCase):
def test_filters_use_positional_arguments(self):
where, args = build_where(StatsFilter(since_hours=2, snake_type="ZenithBattleSnake", source="ladder"))
self.assertIn("g.status = 'finished'", where)
self.assertIn("make_interval(secs => $1)", where)
self.assertIn("g.your_snake_type = $2", where)
self.assertIn("g.source = $3", where)
self.assertEqual(args, [7200.0, "ZenithBattleSnake", "ladder"])
def test_opponent_query_appends_min_games_last(self):
sql, args = opponent_query(StatsFilter(game_type="duel"), min_games=5)
self.assertIn("HAVING count(*) >= $2", sql)
self.assertEqual(args, ["duel", 5])
def test_win_rate_handles_zero_games(self):
self.assertEqual(win_rate(1, 4), " 25.0%")
self.assertEqual(win_rate(0, 0), " -")
def test_pivot_keeps_opponents_faced_by_every_listed_version(self):
records = [
{"opponent": "A", "snake": "Prism", "version": "1.5.0", "wins": 2, "games": 10},
{"opponent": "A", "snake": "Zenith", "version": "1.2.0", "wins": 3, "games": 6},
{"opponent": "B", "snake": "Prism", "version": "1.5.0", "wins": 1, "games": 9},
]
headers, rows = pivot_rows(records, min_games=3)
self.assertEqual(headers, ["opponent", "Prism 1.5.0", "Zenith 1.2.0"])
self.assertEqual(rows, [["A", "2/10 20.0%", "3/6 50.0%"]])
def test_format_table_aligns_columns(self):
table = format_table(["name", "n"], [["long-name", 1]])
self.assertEqual(table.splitlines(), ["name n", "--------- -", "long-name 1"])
if __name__ == "__main__":
unittest.main()