progression: guard set growth against an all-warm-up entry (no work seed, no infinite loop)
This commit is contained in:
1 parent
35181af2aa
commit
bee9b64b78
2 files changed
+13
-1
No files matched your search
@@ -267,7 +267,10 @@ export function applyPrescription(sets, p) {
|
||||
// row that is already there: a session in progress must not lose a set it has logged.
|
||||
const workRows = out.filter(s => !s.warmup)
|
||||
if (p.sets > workRows.length) {
|
||||
const seed = workRows[workRows.length - 1] || out[out.length - 1]
|
||||
// An all-warm-up entry has no work row to seed growth from - growing warm-up copies
|
||||
// would both invent work and never terminate the loop. Leave the entry untouched.
|
||||
if (!workRows.length) return out
|
||||
const seed = workRows[workRows.length - 1]
|
||||
while (out.filter(s => !s.warmup).length < p.sets) out.push({ ...seed, done: false })
|
||||
}
|
||||
return out
|
||||
|
||||
@@ -502,4 +502,13 @@ describe('applyPrescription never touches warm-up rows (round 3)', () => {
|
||||
expect(out.filter(s => s.warmup)).toHaveLength(1) // warm-up untouched
|
||||
expect(out[0]).toEqual({ w: 20, r: 8, done: true, warmup: true })
|
||||
})
|
||||
|
||||
it('an all-warm-up entry terminates and stays untouched', () => {
|
||||
const sets = [
|
||||
{ w: 20, r: 8, done: true, warmup: true },
|
||||
{ w: 25, r: 6, done: true, warmup: true },
|
||||
]
|
||||
const out = applyPrescription(sets, { kind: 'up', weight: 62.5, reps: 5, sets: 4 })
|
||||
expect(out).toEqual(sets) // no work row to seed growth from - nothing grows, no loop
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user