You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
1.8 KiB
89 lines
1.8 KiB
import calculateDiff, {diffString} from "./diff";
|
|
|
|
const programWithoutWarmup = {
|
|
warmupMin: 0,
|
|
warmupCpm: 0,
|
|
cpm: 30,
|
|
cooldownCpm: 20,
|
|
};
|
|
|
|
const programWithWarmup = {
|
|
warmupMin: 10,
|
|
warmupCpm: 25,
|
|
cpm: 30,
|
|
cooldownCpm: 20,
|
|
};
|
|
|
|
describe('diffString', () => {
|
|
it("should show a plus before zero", () => {
|
|
expect(diffString(0)).toBe("+0");
|
|
});
|
|
|
|
it("should show a plus before a positive number", () => {
|
|
expect(diffString(44)).toBe("+44");
|
|
});
|
|
|
|
it("should show a minus when negatives", () => {
|
|
expect(diffString(-12)).toBe("-12");
|
|
});
|
|
});
|
|
|
|
describe("calculateDiff", () => {
|
|
it("should return zero at start", () => {
|
|
const diff = calculateDiff({
|
|
program: programWithoutWarmup,
|
|
minutes: 0,
|
|
seconds: 0,
|
|
calories: 0,
|
|
});
|
|
|
|
expect(diff).toBe(0);
|
|
});
|
|
|
|
it("should expect 300 calories after 0' / 10'", () => {
|
|
const diff = calculateDiff({
|
|
program: programWithoutWarmup,
|
|
minutes: 10,
|
|
seconds: 0,
|
|
calories: 305,
|
|
});
|
|
|
|
expect(diff).toBe(5);
|
|
});
|
|
|
|
it("should expect 865 calories after 10' / 20'50", () => {
|
|
const diff = calculateDiff({
|
|
program: programWithWarmup,
|
|
minutes: 30,
|
|
seconds: 50,
|
|
calories: 250 + 600 + 25 - 17,
|
|
});
|
|
|
|
// Aim: 875
|
|
expect(diff).toBe(-17);
|
|
});
|
|
|
|
it("should expect 755 calories after 10' / 15' / 7'45", () => {
|
|
const diff = calculateDiff({
|
|
program: programWithWarmup,
|
|
cooldownMin: 25,
|
|
minutes: 32,
|
|
seconds: 45,
|
|
calories: 250 + 450 + 140 + 15,
|
|
});
|
|
|
|
expect(diff).toBe(0);
|
|
});
|
|
|
|
it("should expect 325 calories after 5' (half) / 0' / 10'", () => {
|
|
const diff = calculateDiff({
|
|
program: programWithWarmup,
|
|
cooldownMin: 5,
|
|
minutes: 15,
|
|
seconds: 0,
|
|
calories: 325
|
|
});
|
|
|
|
expect(diff).toBe(0);
|
|
});
|
|
});
|