2026-09-04 19:06:19 +02:00
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
|
import fc from 'fast-check';
|
|
|
|
|
import { isSessionEffective, type EffectiveSession } from '../../src/services/killstreak.js';
|
|
|
|
|
|
|
|
|
|
type Exercise = EffectiveSession['exercises'][number];
|
|
|
|
|
|
|
|
|
|
const planSetIdArb = fc.stringOf(fc.char(), { minLength: 1, maxLength: 8 });
|
|
|
|
|
|
|
|
|
|
const exerciseArb: fc.Arbitrary<Exercise> = fc.record({
|
|
|
|
|
hidden: fc.boolean(),
|
|
|
|
|
removed: fc.boolean(),
|
|
|
|
|
planExercise: fc.oneof(
|
|
|
|
|
fc.constant(null),
|
|
|
|
|
fc.array(planSetIdArb).map((ids) => ({ sets: ids.map((id) => ({ id })) })),
|
|
|
|
|
),
|
|
|
|
|
sets: fc.array(
|
|
|
|
|
fc.record({
|
|
|
|
|
planSetId: fc.oneof(fc.constant(null), planSetIdArb),
|
|
|
|
|
reps: fc.oneof(fc.constant(null), fc.integer({ min: 1, max: 100 })),
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const sessionArb: fc.Arbitrary<EffectiveSession> = fc.array(exerciseArb).map((exercises) => ({
|
|
|
|
|
exercises,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
describe('isSessionEffective (property-based)', () => {
|
2026-10-11 17:56:40 +02:00
|
|
|
it('removed exercises never affect the result (hiding does)', () => {
|
2026-09-04 19:06:19 +02:00
|
|
|
fc.assert(
|
|
|
|
|
fc.property(sessionArb, (session) => {
|
2026-10-11 17:56:40 +02:00
|
|
|
const visible = session.exercises.filter((e) => !e.removed);
|
2026-09-04 19:06:19 +02:00
|
|
|
return isSessionEffective(session) === isSessionEffective({ exercises: visible });
|
|
|
|
|
}),
|
|
|
|
|
{ numRuns: 200 },
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('a session where every visible exercise is fully done is effective', () => {
|
|
|
|
|
const fullyDoneExerciseArb = fc.oneof(
|
|
|
|
|
// planned exercise with all plan sets completed
|
|
|
|
|
fc.array(planSetIdArb, { minLength: 1 }).map((ids) => ({
|
|
|
|
|
hidden: false,
|
|
|
|
|
removed: false,
|
|
|
|
|
planExercise: { sets: ids.map((id) => ({ id })) },
|
|
|
|
|
sets: ids.map((id) => ({ planSetId: id, reps: 10 })),
|
|
|
|
|
})),
|
|
|
|
|
// added exercise with at least one set that has reps
|
|
|
|
|
fc.array(
|
|
|
|
|
fc.record({
|
|
|
|
|
planSetId: fc.constant(null as string | null),
|
|
|
|
|
reps: fc.integer({ min: 1, max: 100 }),
|
|
|
|
|
}),
|
|
|
|
|
{ minLength: 1 },
|
|
|
|
|
).map((sets) => ({ hidden: false, removed: false, planExercise: null, sets })),
|
2026-10-11 17:56:40 +02:00
|
|
|
// removed exercise with arbitrary (even incomplete) data — liczone nie jest
|
|
|
|
|
exerciseArb.map((e) => ({ ...e, removed: true })),
|
2026-09-04 19:06:19 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fc.assert(
|
|
|
|
|
fc.property(fc.array(fullyDoneExerciseArb), (exercises) =>
|
|
|
|
|
isSessionEffective({ exercises }),
|
|
|
|
|
),
|
|
|
|
|
{ numRuns: 200 },
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('a visible planned exercise with any missing set makes the session ineffective', () => {
|
|
|
|
|
fc.assert(
|
|
|
|
|
fc.property(
|
|
|
|
|
fc.array(planSetIdArb, { minLength: 1 }),
|
|
|
|
|
fc.array(exerciseArb),
|
|
|
|
|
(missingIds, others) => {
|
|
|
|
|
const incomplete: Exercise = {
|
|
|
|
|
hidden: false,
|
|
|
|
|
removed: false,
|
|
|
|
|
planExercise: { sets: missingIds.map((id) => ({ id })) },
|
|
|
|
|
sets: [],
|
|
|
|
|
};
|
|
|
|
|
return !isSessionEffective({ exercises: [...others, incomplete] });
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
{ numRuns: 200 },
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-11 15:45:19 +02:00
|
|
|
it('an unrecorded extra (bonus) set never changes the result', () => {
|
|
|
|
|
fc.assert(
|
|
|
|
|
fc.property(sessionArb, (session) => {
|
|
|
|
|
// dokleja niezapisaną serię nadprogramową do pierwszego widocznego ćwiczenia
|
|
|
|
|
const withPendingExtra: EffectiveSession = {
|
|
|
|
|
exercises: session.exercises.map((e, i) =>
|
|
|
|
|
i === 0 ? { ...e, sets: [...e.sets, { planSetId: null, reps: null }] } : e,
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
return isSessionEffective(session) === isSessionEffective(withPendingExtra);
|
|
|
|
|
}),
|
|
|
|
|
{ numRuns: 200 },
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-04 19:06:19 +02:00
|
|
|
it('a visible added exercise without sets makes the session ineffective', () => {
|
|
|
|
|
fc.assert(
|
|
|
|
|
fc.property(fc.array(exerciseArb), (others) => {
|
|
|
|
|
const emptyAdded: Exercise = {
|
|
|
|
|
hidden: false,
|
|
|
|
|
removed: false,
|
|
|
|
|
planExercise: null,
|
|
|
|
|
sets: [],
|
|
|
|
|
};
|
|
|
|
|
return !isSessionEffective({ exercises: [...others, emptyAdded] });
|
|
|
|
|
}),
|
|
|
|
|
{ numRuns: 200 },
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|