screen-locker/stronglift_replacement/workout_app/test/models/progression_test.dart
Krzysztof kuhy Rudnicki d35edfc10c workout_app: warmup ×6, per-exercise rests, exercise sheet in Settings
- Warmup is always 6 reps (kWarmupReps): even, one constant.
- Per exercise: rest after success / fail / warmup (0:30-10:00, 15 s
  steps; defaults 3:00/5:00/3:00). Schema v6 NOT NULL DEFAULT columns,
  synced in the Firebase progression record (lenient for older records).
  The notification carries the fail rest so -1 rep re-cuts to it.
- Settings: PER EXERCISE list replaces PROGRESSION THRESHOLDS; each row
  opens the workout tile's sheet and pushes progression when it closes.

Claude-Session: https://claude.ai/code/session_01KeVXsWTuwjmZK5uvbw6vqF

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-27 18:55:56 +02:00

224 lines
6.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter_test/flutter_test.dart';
import 'package:workout_app/models/exercise.dart';
import 'package:workout_app/models/exercise_state.dart';
import 'package:workout_app/models/progression.dart';
ExerciseState _s({
required ProgressionMode mode,
double weight = 20,
int reps = 8,
double maxWeight = 27.5,
int repsHigh = 12,
int repsLow = 6,
}) => ExerciseState(
name: 'X',
weight: weight,
reps: reps,
successStreak: 0,
failStreak: 0,
maxWeight: maxWeight,
successThreshold: 3,
failThreshold: 2,
mode: mode,
repsHigh: repsHigh,
repsLow: repsLow,
hasWarmup: true,
pausedUntil: null,
restSuccessSecs: kDefaultRestSuccessSecs,
restFailSecs: kDefaultRestFailSecs,
restWarmupSecs: kDefaultRestWarmupSecs,
);
void _expectTarget(ProgressionTarget t, double weight, int reps) {
expect((t.weight, t.reps), (weight, reps), reason: '$t');
}
void main() {
group('ProgressionMode.parse', () {
test('reads every storage key back to its mode', () {
for (final m in ProgressionMode.values) {
expect(ProgressionMode.parse(m.storageKey), m);
}
});
test('null (a row from before modes existed) is weight', () {
expect(ProgressionMode.parse(null), ProgressionMode.weight);
});
test('an unknown value falls back to weight', () {
expect(ProgressionMode.parse('sideways'), ProgressionMode.weight);
});
});
group('weight mode (unchanged behaviour)', () {
test('success below the cap adds 2.5 kg', () {
_expectTarget(
targetAfterSuccess(_s(mode: ProgressionMode.weight)),
22.5,
8,
);
});
test('success above the cap clamps to it', () {
final s = _s(mode: ProgressionMode.weight, weight: 26);
_expectTarget(targetAfterSuccess(s), 27.5, 8);
});
test('success at the cap adds a rep instead', () {
final s = _s(mode: ProgressionMode.weight, weight: 27.5);
_expectTarget(targetAfterSuccess(s), 27.5, 9);
});
test('failure drops 2.5 kg, never below zero', () {
_expectTarget(
targetAfterFailure(_s(mode: ProgressionMode.weight)),
17.5,
8,
);
final light = _s(mode: ProgressionMode.weight, weight: 1);
_expectTarget(targetAfterFailure(light), 0, 8);
});
});
group('reps mode', () {
test('success adds a rep and never touches the weight', () {
_expectTarget(targetAfterSuccess(_s(mode: ProgressionMode.reps)), 20, 9);
});
test('failure removes a rep, floored at 1', () {
_expectTarget(targetAfterFailure(_s(mode: ProgressionMode.reps)), 20, 7);
final one = _s(mode: ProgressionMode.reps, reps: 1);
_expectTarget(targetAfterFailure(one), 20, 1);
});
});
group('double progression', () {
const mode = ProgressionMode.doubleProgression;
test('below n: +1 rep', () {
_expectTarget(targetAfterSuccess(_s(mode: mode, reps: 11)), 20, 12);
});
test('at n: +2.5 kg and back to m', () {
_expectTarget(targetAfterSuccess(_s(mode: mode, reps: 12)), 22.5, 6);
});
test('above n (switched in at 30 reps) still promotes', () {
_expectTarget(targetAfterSuccess(_s(mode: mode, reps: 30)), 22.5, 6);
});
test('at n on the weight cap keeps adding reps', () {
final s = _s(mode: mode, reps: 12, weight: 27.5);
_expectTarget(targetAfterSuccess(s), 27.5, 13);
});
test('failure above m removes a rep', () {
_expectTarget(targetAfterFailure(_s(mode: mode, reps: 9)), 20, 8);
});
test('failure at m is the exact inverse of a step up', () {
final s = _s(mode: mode, reps: 6);
final down = targetAfterFailure(s);
_expectTarget(down, 17.5, 12);
final back = targetAfterSuccess(
s.copyWith(weight: down.weight, reps: down.reps),
);
_expectTarget(back, 20, 6);
});
test('failure at m with no weight left stays put', () {
_expectTarget(
targetAfterFailure(_s(mode: mode, reps: 6, weight: 0)),
0,
6,
);
});
});
group('describeTargetChange', () {
final from = _s(mode: ProgressionMode.weight, weight: 20, reps: 8);
test('weight and reps', () {
expect(
describeTargetChange(from, const ProgressionTarget(22.5, 6)),
'22.5 kg × 6',
);
});
test('weight only drops a trailing .0', () {
expect(
describeTargetChange(from, const ProgressionTarget(25, 8)),
'25 kg',
);
});
test('reps only', () {
expect(
describeTargetChange(from, const ProgressionTarget(20, 9)),
'9 reps',
);
});
test('no change', () {
expect(
describeTargetChange(from, const ProgressionTarget(20, 8)),
'same',
);
});
test('toString names both fields', () {
expect(const ProgressionTarget(20, 8).toString(), contains('20'));
});
});
group('ExerciseState', () {
test('initial copies the plan and the plan warmup', () {
const ex = Exercise(
name: 'Situp',
sets: 3,
reps: 30,
weight: 10,
maxWeight: 10,
hasWarmup: false,
);
final s = ExerciseState.initial(ex);
expect(s.weight, 10);
expect(s.reps, 30);
expect(s.maxWeight, 10);
expect(s.hasWarmup, isFalse);
expect(s.mode, ProgressionMode.weight);
expect((s.repsHigh, s.repsLow), (kDefaultRepsHigh, kDefaultRepsLow));
expect((s.successThreshold, s.failThreshold), (3, 2));
});
test('copyWith replaces each field and keeps the rest', () {
final s = _s(mode: ProgressionMode.weight);
final c = s.copyWith(
weight: 1,
reps: 2,
successStreak: 3,
failStreak: 4,
successThreshold: 5,
failThreshold: 1,
mode: ProgressionMode.reps,
repsHigh: 20,
repsLow: 10,
hasWarmup: false,
);
expect(c.name, 'X');
expect(c.maxWeight, 27.5);
expect((c.weight, c.reps, c.successStreak, c.failStreak), (1, 2, 3, 4));
expect((c.successThreshold, c.failThreshold), (5, 1));
expect(
(c.mode, c.repsHigh, c.repsLow, c.hasWarmup),
(ProgressionMode.reps, 20, 10, false),
);
final same = s.copyWith();
expect(
(same.weight, same.reps, same.mode, same.hasWarmup),
(20, 8, ProgressionMode.weight, true),
);
});
});
}