rg-stats
Version:
A library for calculating various rhythm game stats.
247 lines (239 loc) • 4.26 kB
text/typescript
import t from "tap";
import { TestCase } from "../test-utils/test-case";
import { ThrowsToSnapshot } from "../test-utils/throw-snapshot";
import { calculate } from "./ddr-flare";
const testCases = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
];
t.test("DDR Flare Tests", (t) => {
function MakeTestCase(internalChartLevel: number, flareLevel: number, flare: number): TestCase {
return (t) => {
const result = calculate(internalChartLevel, flareLevel);
t.equal(
result,
flare,
`Flare ${flareLevel} on level ${internalChartLevel} chart should be worth ${flare} flare points. Got ${result} instead.`
);
};
}
// This is just one big table stolen from bemaniwiki.
for (const testCase of testCases) {
MakeTestCase(testCase[0], testCase[1], testCase[2])(t);
}
t.end();
});
t.test("DDR Flare Validation Tests", (t) => {
ThrowsToSnapshot(t, () => calculate(-1, 0), "Should throw if chart level is negative.");
ThrowsToSnapshot(t, () => calculate(20, 0), "Should throw if chart level is greater than 19.");
ThrowsToSnapshot(t, () => calculate(1, -1), "Should throw if flare level is negative.");
ThrowsToSnapshot(t, () => calculate(1, 11), "Should throw if flare level is greater than 10.");
t.end();
});