mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-11 00:38:28 +03:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { CalculateESD, ESDCompare, PercentCompare } from "./esd";
|
|
import { GetGamePTConfig } from "../config/config";
|
|
import t from "tap";
|
|
|
|
function approx(t: Tap.Test, given: number, recieved: number, acc = 0.01) {
|
|
if (Math.abs(given - recieved) < acc) {
|
|
return t.pass();
|
|
}
|
|
|
|
return t.fail(`Expected ${given} to be within ${acc} of ${recieved}.`);
|
|
}
|
|
|
|
const gptConfig = GetGamePTConfig("iidx", "SP");
|
|
|
|
if (!gptConfig.supportsESD) {
|
|
throw new Error(`IIDX:SP no longer supports esd, these tests won't work.`);
|
|
}
|
|
|
|
const judgementWindows = gptConfig.judgementWindows;
|
|
|
|
t.test("#CalculateESD", (t) => {
|
|
const jdg = judgementWindows;
|
|
|
|
approx(t, CalculateESD(jdg, 0.8), 17.58);
|
|
approx(t, CalculateESD(jdg, 0), 200);
|
|
t.throws(() => CalculateESD(jdg, 0, true));
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test("#ESDCompare", (t) => {
|
|
approx(t, ESDCompare(16, 14), 6.42);
|
|
approx(t, ESDCompare(16, 14, 1), ESDCompare(16, 14));
|
|
approx(t, ESDCompare(0, 200, 1), -68.27);
|
|
|
|
t.end();
|
|
});
|
|
|
|
t.test("#PercentCompare", (t) => {
|
|
const jdg = judgementWindows;
|
|
|
|
approx(t, PercentCompare(jdg, 0.99, 0.98), -5.53);
|
|
approx(t, PercentCompare(jdg, 0.99, 0.98), PercentCompare(jdg, 0.99, 0.98, 1));
|
|
|
|
t.end();
|
|
});
|