Tests for FreeRide intensities XP

This commit is contained in:
Rene Saarsoo 2020-11-20 17:50:45 +02:00
parent 8d0446756c
commit 7d20ed3ced
2 changed files with 32 additions and 5 deletions

View File

@ -1,7 +1,7 @@
import { xp } from "./xp"; import { xp } from "./xp";
import { Interval } from "../ast"; import { Interval } from "../ast";
import { Duration } from "../Duration"; import { Duration } from "../Duration";
import { ConstantIntensity, RangeIntensity } from "../Intensity"; import { ConstantIntensity, FreeIntensity, RangeIntensity } from "../Intensity";
import { RepeatedInterval } from "../detectRepeats"; import { RepeatedInterval } from "../detectRepeats";
describe("xp()", () => { describe("xp()", () => {
@ -68,6 +68,33 @@ describe("xp()", () => {
}); });
}); });
describe("FreeRide interval", () => {
const createTestInterval = (seconds: number): Interval => ({
type: "FreeRide",
duration: new Duration(seconds),
intensity: new FreeIntensity(),
comments: [],
});
[
[54, 5],
[55, 5],
[56, 5],
[57, 5],
[58, 5],
[59, 5],
[61, 6],
[62, 6],
[63, 6],
[64, 6],
[3 * 60, 17],
].forEach(([seconds, expectedXp]) => {
it(`${seconds}s produces ${expectedXp} XP`, () => {
expect(xp([createTestInterval(seconds)])).toEqual(expectedXp);
});
});
});
describe("Repeated interval", () => { describe("Repeated interval", () => {
const createTestInterval = (times: number, [onSeconds, offSeconds]: number[]): RepeatedInterval => ({ const createTestInterval = (times: number, [onSeconds, offSeconds]: number[]): RepeatedInterval => ({
type: "repeat", type: "repeat",

View File

@ -6,7 +6,7 @@ import { totalDuration } from "./totalDuration";
const intervalXp = (interval: Interval | RepeatedInterval): number => { const intervalXp = (interval: Interval | RepeatedInterval): number => {
if (interval.type === "repeat") { if (interval.type === "repeat") {
// 11 XP per minute (1 XP for every 5.05 seconds) // 11.9 XP per minute (1 XP for every 5.05 seconds)
const duration = totalDuration(interval.intervals).seconds * interval.times; const duration = totalDuration(interval.intervals).seconds * interval.times;
return Math.floor(duration / 5.05); // Suitable numbers are: 5.01 .. 5.09 return Math.floor(duration / 5.05); // Suitable numbers are: 5.01 .. 5.09
} else { } else {
@ -14,11 +14,11 @@ const intervalXp = (interval: Interval | RepeatedInterval): number => {
// 6 XP per minute (1XP for every 10 seconds) // 6 XP per minute (1XP for every 10 seconds)
return Math.floor(interval.duration.seconds / 10); return Math.floor(interval.duration.seconds / 10);
} else if (interval.intensity instanceof ConstantIntensity) { } else if (interval.intensity instanceof ConstantIntensity) {
// 10 XP per minute (1XP for every 5.56 seconds) // 10.8 XP per minute (1XP for every 5.56 seconds)
return Math.floor(interval.duration.seconds / 5.56); return Math.floor(interval.duration.seconds / 5.56);
} else if (interval.intensity instanceof FreeIntensity) { } else if (interval.intensity instanceof FreeIntensity) {
// 5 XP per minute // 5.9 XP per minute (1XP for every 10.1 seconds)
return Math.round(interval.duration.seconds / 60) * 5; return Math.floor(interval.duration.seconds / 10.1);
} else { } else {
throw new Error("Unknown type of intensity"); throw new Error("Unknown type of intensity");
} }