fix doc weight to show real doc instead of forcing 35-51 range and also fixed bug target weight using total days as reference for target weight instead of doc weight
This commit is contained in:
1 parent
4439e3b7b1
commit
75eb218558
8 files changed
+76
-34
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { weightStandardData } from '../../mockData/weightStandardData.ts';
|
||||
import { getTargetGainForAge, getTargetWeightForAge } from '../weight.ts';
|
||||
|
||||
function rowForDoc(docWeight: number) {
|
||||
return weightStandardData.data.find((row) => row.day === docWeight)!;
|
||||
}
|
||||
|
||||
describe('getTargetWeightForAge', () => {
|
||||
it('uses the exact DOC-weight row and age column', () => {
|
||||
const row = rowForDoc(42);
|
||||
expect(getTargetWeightForAge(1, 42)).toBe(row.values[0]);
|
||||
expect(getTargetWeightForAge(35, 42)).toBe(row.values[34]);
|
||||
});
|
||||
|
||||
it('clamps below-range DOC weight to the 35 g row', () => {
|
||||
const row = rowForDoc(35);
|
||||
expect(getTargetWeightForAge(7, 20)).toBe(row.values[6]);
|
||||
expect(getTargetWeightForAge(7, 30)).toBe(row.values[6]);
|
||||
});
|
||||
|
||||
it('clamps above-range DOC weight to the 51 g row', () => {
|
||||
const row = rowForDoc(51);
|
||||
expect(getTargetWeightForAge(7, 52)).toBe(row.values[6]);
|
||||
expect(getTargetWeightForAge(7, 60)).toBe(row.values[6]);
|
||||
});
|
||||
|
||||
it('returns null for ages outside 1..35', () => {
|
||||
expect(getTargetWeightForAge(0, 42)).toBeNull();
|
||||
expect(getTargetWeightForAge(36, 42)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTargetGainForAge', () => {
|
||||
it('returns day-over-day delta from the DOC-weight row', () => {
|
||||
const row = rowForDoc(40);
|
||||
expect(getTargetGainForAge(2, 40)).toBe(row.values[1]! - row.values[0]!);
|
||||
});
|
||||
|
||||
it('returns null for age 1', () => {
|
||||
expect(getTargetGainForAge(1, 40)).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user