45 lines
2.7 KiB
TypeScript
45 lines
2.7 KiB
TypeScript
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);
|
|
});
|
|
|
|
test('전체 난이도 추천은 Easy와 Normal을 포함하고 곡별 최고점만 합산한다', () => {
|
|
const charts = ['easy', 'normal', 'hard', 'expert'].map((difficulty, index) => ({
|
|
songId: 'song', title: 'Song', difficulty, singerCharacterIds: ['leader'],
|
|
theoreticalMaxScore: 20000 - index * 5000, expectedScore: 1000
|
|
}));
|
|
assert.deepEqual(leaderRatingCharts(charts, 'leader', 'all', Date.now()), charts);
|
|
assert.deepEqual(leaderRatingCharts(charts, 'leader', 'normal', Date.now()), [charts[1]]);
|
|
assert.equal(rankSongs(charts)[0].difficulty, 'easy');
|
|
assert.equal(leaderRating(charts), 4);
|
|
});
|