feat: add leader rating song recommendations

This commit is contained in:
2026-09-07 13:55:55 +09:00
parent 297eb1863c
commit 907c11b0e6
9 changed files with 625 additions and 15 deletions
+33
View File
@@ -0,0 +1,33 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { leaderRating, leaderRatingCharts, rankSongCharts, rankSongs, songRating } from './song-rating.ts';
test('레이팅은 5000점 단위로 올림하며 잘못된 점수를 거부한다', () => {
assert.deepEqual([0, 1, 5000, 5001, 1234567].map(songRating), [0, 1, 1, 2, 247]);
for (const score of [-1, NaN, Infinity]) assert.throws(() => songRating(score));
});
test('리더 가창곡의 공개된 채보만 선택한다', () => {
const charts = [
{ songId: 'solo', title: 'Solo', difficulty: 'expert', singerCharacterIds: ['leader'] },
{ songId: 'solo', title: 'Solo', difficulty: 'hard', singerCharacterIds: ['leader'] },
{ songId: 'group', title: 'Group', difficulty: 'expert', singerCharacterIds: ['other', 'leader'], releaseTime: 200 },
{ songId: 'other', title: 'Other', difficulty: 'expert', singerCharacterIds: ['other'] },
{ songId: 'unknown', title: 'Unknown', difficulty: 'expert', singerCharacterIds: [] }
];
assert.deepEqual(leaderRatingCharts(charts, 'leader', 'expert', 199), [charts[0]]);
assert.deepEqual(leaderRatingCharts(charts, 'leader', 'both', 200), charts.slice(0, 3));
assert.deepEqual(leaderRatingCharts(charts, '', 'both', 200), []);
});
test('고점 순위와 상위 3곡 합계는 동일 곡의 난이도를 중복 집계하지 않는다', () => {
const row = (songId: string, score: number, difficulty = 'expert') => ({
songId, title: songId, difficulty, theoreticalMaxScore: score, expectedScore: score / 2
});
const results = [row('a', 5001), row('b', 10001), row('a', 20001, 'hard'), row('c', 9999), row('d', 5000)];
assert.deepEqual(rankSongCharts(results).map((item) => [item.songId, item.difficulty]), [['a', 'hard'], ['b', 'expert'], ['c', 'expert'], ['a', 'expert'], ['d', 'expert']]);
assert.deepEqual(rankSongs(results).map((item) => [item.songId, item.difficulty]), [['a', 'hard'], ['b', 'expert'], ['c', 'expert'], ['d', 'expert']]);
assert.equal(leaderRating(results), 10);
assert.equal(leaderRating([]), 0);
assert.equal(results[0].theoreticalMaxScore, 5001);
});