Tests for FreeRide intensities XP
This commit is contained in:
parent
8d0446756c
commit
7d20ed3ced
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue