import { test } from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import { rateLol, rateValorant, type MatchPlayer, type MatchRound } from '@gvr/shared'; /** OP.GG 공식 MCP 에서 받은 실제 경기 (tools/opscore-fit/make_fixture.py). 우리 계산이 실제 OP.GG 점수와 가까운지 본다 */ const sample = JSON.parse(fs.readFileSync(new URL('./fixtures/opgg-sample.json', import.meta.url), 'utf8')); test('기록 점수 (롤): 실제 OP.GG OP스코어와 평균 오차 · 팀 최하위 일치', () => { let err = 0; let n = 0; let teams = 0; let lowestHit = 0; for (const g of sample.lol) { const players = g.players as (MatchPlayer & { opgg: number })[]; const r = rateLol(players, g.minutes, g.allyWin); for (const p of players) { err += Math.abs(r.get(p.puuid)!.score - p.opgg); n++; } for (const team of ['BLUE', 'RED']) { const ps = players.filter((p) => p.team === team); teams++; const ours = ps.reduce((a, b) => (r.get(a.puuid)!.score <= r.get(b.puuid)!.score ? a : b)); const theirs = ps.reduce((a, b) => (a.opgg <= b.opgg ? a : b)); if (ours === theirs) lowestHit++; } // 이긴 팀 1등 MVP, 진 팀 1등 ACE const badges = [...r.values()].map((x) => x.badge).filter(Boolean).sort(); assert.deepEqual(badges, ['ACE', 'MVP']); } const mae = err / n; assert.ok(mae < 0.75, `평균 오차 ${mae.toFixed(2)}`); assert.ok(lowestHit / teams >= 0.75, `팀 최하위 일치 ${lowestHit}/${teams}`); }); test('기록 점수 (발로란트): 실제 OP.GG OP스코어와 평균 오차', () => { let err = 0; for (const v of sample.valorant) { const rounds = Array.from({ length: v.rounds }, (_, i) => ({ win: i < v.wonRounds }) as MatchRound); const r = rateValorant([v.player], rounds).get('v')!; assert.equal(r.basic, false); err += Math.abs(r.score - v.opgg); } const mae = err / sample.valorant.length; assert.ok(mae < 0.7, `평균 오차 ${mae.toFixed(2)}`); }); test('기록 점수: 추가 지표가 없는 예전 경기는 기본 기록 모델, 설명은 상식 방향만', () => { const g = sample.lol[0]; const bare = g.players.map(({ stats: _s, ...p }: any) => p); const r = rateLol(bare, g.minutes, g.allyWin); assert.ok([...r.values()].every((x) => x.basic && x.score >= 0 && x.score <= 10)); // 데스가 가장 많은 사람에게 "데스" 가 강점으로 붙지 않는다 const full = rateLol(g.players, g.minutes, g.allyWin); for (const x of full.values()) for (const part of x.parts) if (/데스/.test(part.text)) assert.equal(part.good, false, part.text); });