add BMI calculator combination tests
This commit is contained in:
parent
bbd03bfeed
commit
951d102ac0
1 changed files with 27 additions and 0 deletions
|
|
@ -278,3 +278,30 @@ test('BMI sample calculation preserves fractional-age interpolation', async () =
|
|||
assert.equal(assessment.percentile, 79.26);
|
||||
assert.equal(assessment.classification.text, 'Healthy Weight');
|
||||
});
|
||||
|
||||
test('BMI calculator preserves legacy outputs across sex/age/body-size combinations', async () => {
|
||||
const bmi = await import('../public/js/calculators/bmi.js');
|
||||
const raw = fs.readFileSync(path.join(__dirname, '..', 'public', 'data', 'calculators', 'bmi-lms.json'), 'utf8');
|
||||
const data = JSON.parse(raw).lms;
|
||||
const cases = [
|
||||
{ name: 'male healthy 10y', sex: 'male', ageYears: 10, weightKg: 32, heightCm: 140, ageMonths: 120, bmi: 16.3, z: -0.17, percentile: 43.42, classification: 'Healthy Weight', pctOf95: 74, bmi95: 22.2 },
|
||||
{ name: 'female obese 8y', sex: 'female', ageYears: 8, weightKg: 35, heightCm: 130, ageMonths: 96, bmi: 20.7, z: 1.65, percentile: 95.03, classification: 'Obese (Class 1)', pctOf95: 100, bmi95: 20.7 },
|
||||
{ name: 'male class 2 severe 12y', sex: 'male', ageYears: 12, weightKg: 70, heightCm: 150, ageMonths: 144, bmi: 31.1, z: 2.32, percentile: 98.97, classification: 'Class 2 Severe Obesity', pctOf95: 128, bmi95: 24.2 },
|
||||
{ name: 'female underweight 5y', sex: 'female', ageYears: 5, weightKg: 13, heightCm: 110, ageMonths: 60, bmi: 10.7, z: -7.66, percentile: 0, classification: 'Underweight', pctOf95: 59, bmi95: 18.3 },
|
||||
{ name: 'male fractional age 10.5y', sex: 'male', ageYears: 10.5, weightKg: 40, heightCm: 145, ageMonths: 126, bmi: 19.0, z: 0.82, percentile: 79.26, classification: 'Healthy Weight', pctOf95: 84, bmi95: 22.7 },
|
||||
{ name: 'female healthy 15y', sex: 'female', ageYears: 15, weightKg: 52, heightCm: 162, ageMonths: 180, bmi: 19.8, z: -0.04, percentile: 48.44, classification: 'Healthy Weight', pctOf95: 70, bmi95: 28.1 },
|
||||
{ name: 'male overweight 6y', sex: 'male', ageYears: 6, weightKg: 26, heightCm: 120, ageMonths: 72, bmi: 18.1, z: 1.51, percentile: 93.42, classification: 'Overweight', pctOf95: 98, bmi95: 18.4 },
|
||||
{ name: 'female class 3 severe 14y', sex: 'female', ageYears: 14, weightKg: 100, heightCm: 155, ageMonths: 168, bmi: 41.6, z: 2.61, percentile: 99.55, classification: 'Class 3 Severe Obesity', pctOf95: 153, bmi95: 27.3 }
|
||||
];
|
||||
|
||||
cases.forEach((expected) => {
|
||||
const actual = bmi.calculateBMIAssessment(data, expected.sex, expected.ageYears, expected.weightKg, expected.heightCm);
|
||||
assert.equal(actual.ageMonths, expected.ageMonths, expected.name + ' ageMonths');
|
||||
assert.equal(Number(actual.bmi.toFixed(1)), expected.bmi, expected.name + ' bmi');
|
||||
assert.equal(Number(actual.z.toFixed(2)), expected.z, expected.name + ' z');
|
||||
assert.equal(actual.percentile, expected.percentile, expected.name + ' percentile');
|
||||
assert.equal(actual.classification.text, expected.classification, expected.name + ' classification');
|
||||
assert.equal(Number(actual.classification.pctOf95.toFixed(0)), expected.pctOf95, expected.name + ' pctOf95');
|
||||
assert.equal(Number(actual.classification.bmi95.toFixed(1)), expected.bmi95, expected.name + ' bmi95');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue