diff --git a/src/stats/xp.test.ts b/src/stats/xp.test.ts index 01a4388..926416f 100644 --- a/src/stats/xp.test.ts +++ b/src/stats/xp.test.ts @@ -1,7 +1,7 @@ import { xp } from "./xp"; import { Interval } from "../ast"; import { Duration } from "../Duration"; -import { ConstantIntensity, RangeIntensity } from "../Intensity"; +import { ConstantIntensity, FreeIntensity, RangeIntensity } from "../Intensity"; import { RepeatedInterval } from "../detectRepeats"; 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", () => { const createTestInterval = (times: number, [onSeconds, offSeconds]: number[]): RepeatedInterval => ({ type: "repeat", diff --git a/src/stats/xp.ts b/src/stats/xp.ts index 75763fb..be01de8 100644 --- a/src/stats/xp.ts +++ b/src/stats/xp.ts @@ -6,7 +6,7 @@ import { totalDuration } from "./totalDuration"; const intervalXp = (interval: Interval | RepeatedInterval): number => { 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; return Math.floor(duration / 5.05); // Suitable numbers are: 5.01 .. 5.09 } else { @@ -14,11 +14,11 @@ const intervalXp = (interval: Interval | RepeatedInterval): number => { // 6 XP per minute (1XP for every 10 seconds) return Math.floor(interval.duration.seconds / 10); } 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); } else if (interval.intensity instanceof FreeIntensity) { - // 5 XP per minute - return Math.round(interval.duration.seconds / 60) * 5; + // 5.9 XP per minute (1XP for every 10.1 seconds) + return Math.floor(interval.duration.seconds / 10.1); } else { throw new Error("Unknown type of intensity"); }