Functional Weave
Code in TypeScript

health.bmi@1.0.1

vectors.json

3,028 bytes · view raw

[
  { "name": "70 kg, 175 cm: 22.857 is 22.9, healthy weight", "args": [70, 175], "expect": { "value": 22.9, "category": "healthy-weight" } },
  { "name": "63.5 kg, 165.1 cm (10 st, 5 ft 5 in): 23.3", "args": [63.5, 165.1], "expect": { "value": 23.3, "category": "healthy-weight" } },
  { "name": "50 kg, 180 cm: 15.4, underweight", "args": [50, 180], "expect": { "value": 15.4, "category": "underweight" } },
  { "name": "exactly 18.5 is the bottom of healthy weight", "args": [74, 200], "expect": { "value": 18.5, "category": "healthy-weight" } },
  { "name": "18.425 rounds to 18.4, underweight", "args": [73.7, 200], "expect": { "value": 18.4, "category": "underweight" } },
  { "name": "exactly 24.9 is still healthy weight", "args": [99.6, 200], "expect": { "value": 24.9, "category": "healthy-weight" } },
  { "name": "24.975 is reported 25.0 and is overweight: a naive < 25 on the raw value says healthy", "args": [99.9, 200], "expect": { "value": 25.0, "category": "overweight" } },
  { "name": "29.925 rounds to 29.9, overweight", "args": [119.7, 200], "expect": { "value": 29.9, "category": "overweight" } },
  { "name": "exactly 30.0 is obesity class 1", "args": [120, 200], "expect": { "value": 30.0, "category": "obesity-class-1" } },
  { "name": "34.975 is reported 35.0, obesity class 2", "args": [139.9, 200], "expect": { "value": 35.0, "category": "obesity-class-2" } },
  { "name": "92 kg, 160 cm: 35.9375 is 35.9, obesity class 2", "args": [92, 160], "expect": { "value": 35.9, "category": "obesity-class-2" } },
  { "name": "39.925 rounds to 39.9, obesity class 2", "args": [159.7, 200], "expect": { "value": 39.9, "category": "obesity-class-2" } },
  { "name": "39.975 is reported 40.0, obesity class 3", "args": [159.9, 200], "expect": { "value": 40.0, "category": "obesity-class-3" } },
  { "name": "110 kg, 160 cm: 42.97 is 43.0, obesity class 3", "args": [110, 160], "expect": { "value": 43.0, "category": "obesity-class-3" } },
  { "name": "the lowest accepted weight and height", "args": [10, 50], "expect": { "value": 40.0, "category": "obesity-class-3" } },
  { "name": "the highest accepted weight and height", "args": [650, 272], "expect": { "value": 87.9, "category": "obesity-class-3" } },
  { "name": "height in metres is refused, not read as 1.75 cm", "args": [70, 1.75], "expectError": "heightCm must be a number from 50 to 272 cm" },
  { "name": "zero weight is refused", "args": [0, 175], "expectError": "weightKg must be a number from 10 to 650 kg" },
  { "name": "negative weight is refused", "args": [-70, 175], "expectError": "weightKg must be a number from 10 to 650 kg" },
  { "name": "weight in pounds past the maximum is refused", "args": [700, 175], "expectError": "weightKg must be a number from 10 to 650 kg" },
  { "name": "a height over 272 cm is refused", "args": [70, 1750], "expectError": "heightCm must be a number from 50 to 272 cm" },
  { "name": "a weight given as text is refused", "args": ["70", 175], "expectError": "weightKg must be a number from 10 to 650 kg" }
]