Files

85 lines
4.9 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { events, games, players } from '../src/design-previews/internal-stats/data.ts';
import { aggregateRows, filterEvents, gamesForSeason, playerGames, seasonMetrics } from '../src/design-previews/internal-stats/model.ts';
test('season metrics distinguish official results from analyzable records', () => {
const june = seasonMetrics('2026-2');
assert.equal(june.events, 6);
assert.equal(june.sets, 62);
assert.equal(june.ready, 54);
assert.equal(june.players, 40);
assert.equal(gamesForSeason('all').length, games.length);
assert.equal(gamesForSeason('2026-1').length + june.sets, games.length);
assert.ok(gamesForSeason('2026-1').every(g => g.eventId.startsWith('may-')));
});
test('every event keeps its official series, opponents, scores, and complete set order', () => {
for (const event of events) {
let n = 0;
for (const series of event.series) {
assert.equal(series.scoreA + series.scoreB, series.games.length);
assert.equal(series.winner, series.scoreA > series.scoreB ? series.a : series.b);
series.games.forEach((game, index) => {
assert.equal(game.number, ++n);
assert.equal(game.ordinal, index + 1);
assert.equal(game.seriesId, series.id);
assert.deepEqual(new Set([game.blue, game.red]), new Set([series.a, series.b]));
assert.equal(game.participants.length, 10);
assert.equal(game.participants.filter(p => p.won).length, 5);
assert.equal(game.participants.reduce((n, p) => n + p.kills, 0), game.participants.reduce((n, p) => n + p.deaths, 0));
});
}
}
});
test('date, event type, participant, and search filters compose', () => {
const base = { season: '2026-2', query: '', format: 'all', from: '', to: '', player: '' };
assert.deepEqual(filterEvents({ ...base, from: '2026-06-23', to: '2026-06-23' }).map(e => e.id), ['tuesday-pair']);
assert.equal(filterEvents({ ...base, from: '2026-06-28', to: '2026-06-20' }).length, 0);
assert.ok(filterEvents({ ...base, format: 'pair' }).every(e => e.format === 'pair'));
assert.ok(filterEvents({ ...base, query: ' 정기 멸망전 ' }).every(e => e.id === 'summer-finals'));
const player = players[0];
assert.deepEqual(filterEvents({ ...base, query: player.name }).map(e => e.id), filterEvents({ ...base, player: player.id }).map(e => e.id));
assert.equal(filterEvents({ ...base, query: '존재하지않는검색어' }).length, 0);
});
test('lane selection recalculates all metrics from actual appearances', () => {
const laneRows = aggregateRows('2026-2', 'JUNGLE', 0, 'games');
const row = laneRows.find(r => r.id === 'p0')!; // This top player has role-swapped games.
const overall = aggregateRows('2026-2', 'all', 0, 'games').find(r => r.id === row.id)!;
const played = playerGames(row.id, '2026-2', 'JUNGLE');
assert.ok(row.games > 0 && row.games < overall.games);
assert.ok(played.every(v => v.game.evidence === 'ready' && v.participant.lane === 'JUNGLE'));
assert.equal(row.games, played.length);
const sum = (key: 'kills' | 'deaths' | 'assists') => played.reduce((n, v) => n + v.participant[key], 0);
assert.equal(row.kda, (sum('kills') + sum('assists')) / Math.max(sum('deaths'), 1));
assert.equal(row.winRate, played.filter(v => v.participant.won).length / played.length * 100);
assert.equal(row.gpm, played.reduce((n, v) => n + v.participant.gold / (v.game.duration / 60), 0) / played.length);
assert.equal(row.kp, played.reduce((n, v) => n + v.participant.kp, 0) / played.length);
assert.equal(row.cspm, played.reduce((n, v) => n + v.participant.cs / (v.game.duration / 60), 0) / played.length);
});
test('qualified players precede low samples and metric sorting works in either direction', () => {
for (const direction of ['asc', 'desc'] as const) {
const rows = aggregateRows('2026-2', 'all', 20, 'kda', direction);
const eligible = rows.filter(r => r.games >= 20);
assert.deepEqual(rows.slice(0, eligible.length), eligible);
assert.ok(rows.length > eligible.length && eligible.length > 0);
for (let i = 1; i < eligible.length; i++) assert.ok(direction === 'asc' ? eligible[i].kda >= eligible[i - 1].kda : eligible[i].kda <= eligible[i - 1].kda);
assert.deepEqual(rows.map(r => r.rank), rows.map((_, i) => i + 1));
}
});
test('season records link to the same season and single-game GPM is reproducible', () => {
for (const season of ['2026-1', '2026-2', 'all']) {
const metrics = seasonMetrics(season), best = metrics.bestGpm!;
const scoped = gamesForSeason(season);
assert.ok(scoped.some(g => g.id === best.game.id));
assert.equal(best.game.evidence, 'ready');
assert.equal(best.gpm, best.p.gold / (best.game.duration / 60));
assert.ok(metrics.topKda!.games >= 5 && metrics.topKp!.games >= 5 && metrics.topCs!.games >= 5);
for (const g of scoped.filter(g => g.evidence === 'ready')) for (const p of g.participants) assert.ok(p.gold / (g.duration / 60) <= best.gpm);
}
});