curated2: !69; Thai/Hungarian get the swap strings; pt-BR guard re-fingerprinted
This commit is contained in:
commit
148ef9fbbb
21 files changed
+145
-17
No files matched your search
@@ -19,6 +19,7 @@
|
||||
import { modeOf, repStep, rerampWarmups } from './history.js'
|
||||
import { EXIDX } from './exercises.js'
|
||||
import { isWarmupRow } from './workout-model.js'
|
||||
import { normalizeRepRange } from './rep-range.js'
|
||||
|
||||
export const POLICIES = ['off', 'linear', 'greyskull', 'double', 'time']
|
||||
|
||||
@@ -214,8 +215,9 @@ export function nextPrescription(S, cfg, routine) {
|
||||
return { policy, kind: 'up', weight: 0, reps: next, why: ['Bodyweight — every rep last time, so go for {0} this time.', next] }
|
||||
}
|
||||
if (policy === 'double') {
|
||||
const top = cfg.reps || last.goal || 10
|
||||
const bottom = Math.min(cfg.repsMin || Math.max(1, top - 2), top)
|
||||
const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin, repStep(cfg))
|
||||
const top = range.reps
|
||||
const bottom = range.repsMin
|
||||
if (last.ok) return { policy, kind: 'up', weight: snap(w + inc, inc), reps: bottom, why: ['Top of the rep range in every set — {0} {1} more, back to {2} reps.', inc, unit, bottom] }
|
||||
if (stalls >= deloadAt) {
|
||||
const dw = deloadTo(w, inc)
|
||||
|
||||
@@ -311,6 +311,13 @@ describe('double progression', () => {
|
||||
expect(p.reps).toBe(8)
|
||||
expect(p.weight).toBe(35) // 40 × 0.9 = 36 → nearest loadable 2.5 step
|
||||
})
|
||||
|
||||
it('normalizes persisted per-side bounds before prescribing', () => {
|
||||
const perSide = { ...cfg, reps: 13, repsMin: 7, side: true }
|
||||
const p = nextPrescription(hist(LIFT, [[40, 12, 12, 12]], { sets: 3, reps: 13 }), perSide)
|
||||
expect(p.kind).toBe('hold')
|
||||
expect(p.reps).toBe(14)
|
||||
})
|
||||
})
|
||||
|
||||
describe('timed progression', () => {
|
||||
|
||||
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
|
||||
.sort(byCodeUnit)
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
|
||||
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(293)
|
||||
expect(inherited).toHaveLength(449)
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(331)
|
||||
expect(inherited).toHaveLength(448)
|
||||
// If this fails, review the changed keys and wording before accepting a new hash. From
|
||||
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('09c4fa5e04c8d3ea21916a6c07f074a35013b33d5d945ecfc13cd54cc8b7d41d')
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('1f0f51af8e2e4b778db6d3d89cb7a6539091c9bc6e1cf0f864a590e586b03180')
|
||||
})
|
||||
|
||||
test('does not leak European Portuguese UI terms', () => {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Normalize the two bounds used by double progression.
|
||||
// `reps` is the upper bound and `repsMin` is the lower bound in persisted configs.
|
||||
export function normalizeRepRange(reps, repsMin, stride = 1) {
|
||||
const step = Number.isInteger(stride) && stride > 0 ? stride : 1
|
||||
const upper = align(positiveInt(reps, 10), step)
|
||||
const lower = align(positiveInt(repsMin, Math.max(1, upper - 2)), step)
|
||||
return lower >= upper
|
||||
? { reps: lower + step, repsMin: lower }
|
||||
: { reps: upper, repsMin: lower }
|
||||
}
|
||||
|
||||
function align(value, stride) {
|
||||
return Math.max(stride, Math.ceil(value / stride) * stride)
|
||||
}
|
||||
|
||||
function positiveInt(value, fallback) {
|
||||
const n = Number(value)
|
||||
return Number.isFinite(n) && n > 0 ? Math.max(1, Math.round(n)) : fallback
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { normalizeRepRange } from './rep-range.js'
|
||||
|
||||
describe('normalizeRepRange', () => {
|
||||
it('keeps valid positive integer bounds unchanged', () => {
|
||||
expect(normalizeRepRange(12, 8)).toEqual({ reps: 12, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('rounds bounds to positive integers', () => {
|
||||
expect(normalizeRepRange(12.4, 7.6)).toEqual({ reps: 12, repsMin: 8 })
|
||||
expect(normalizeRepRange(0, -2)).toEqual({ reps: 10, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('raises the upper bound when the lower bound reaches it', () => {
|
||||
expect(normalizeRepRange(8, 8)).toEqual({ reps: 9, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('raises the upper bound when the lower bound exceeds it', () => {
|
||||
expect(normalizeRepRange(8, 12)).toEqual({ reps: 13, repsMin: 12 })
|
||||
})
|
||||
|
||||
it('keeps the lower bound at least one below a lowered upper bound', () => {
|
||||
expect(normalizeRepRange(6, 8)).toEqual({ reps: 9, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('supplies a usable default lower bound for a small upper bound', () => {
|
||||
expect(normalizeRepRange(1, undefined)).toEqual({ reps: 2, repsMin: 1 })
|
||||
})
|
||||
|
||||
it('aligns both bounds to an even stride', () => {
|
||||
expect(normalizeRepRange(13, 7, 2)).toEqual({ reps: 14, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('keeps a valid gap when per-side bounds are invalid', () => {
|
||||
expect(normalizeRepRange(8, 9, 2)).toEqual({ reps: 12, repsMin: 10 })
|
||||
expect(normalizeRepRange(0, -2, 2)).toEqual({ reps: 10, repsMin: 8 })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user