Functional Weave
Code in TypeScript

agri.stocking-rate@1.0.1

vectors.json

4,674 bytes · view raw

[
  { "name": "Eurostat: 100 dairy cows and 80 yearlings on 120 ha is 156 LU, 1.3 LU/ha", "args": ["eurostat", [{ "category": "dairy-cows", "count": 100 }, { "category": "bovine-1-to-2-years", "count": 80 }], 120], "expect": { "livestockUnits": 156, "unitsPerHectare": 1.3, "lines": [{ "category": "dairy-cows", "count": 100, "coefficient": 1, "livestockUnits": 100 }, { "category": "bovine-1-to-2-years", "count": 80, "coefficient": 0.7, "livestockUnits": 56 }] } },
  { "name": "Countryside Stewardship: 300 lowland ewes with lambs and 20 suckler cows on 40 ha", "args": ["uk-countryside-stewardship", [{ "category": "lowland-ewe-and-lamb", "count": 300 }, { "category": "cattle-over-2-years", "count": 20 }], 40], "expect": { "livestockUnits": 56, "unitsPerHectare": 1.4, "lines": [{ "category": "lowland-ewe-and-lamb", "count": 300, "coefficient": 0.12, "livestockUnits": 36 }, { "category": "cattle-over-2-years", "count": 20, "coefficient": 1, "livestockUnits": 20 }] } },
  { "name": "16,000 laying hens on 3 ha is 224 LU, 74.67 LU/ha", "args": ["eurostat", [{ "category": "laying-hens", "count": 16000 }], 3], "expect": { "livestockUnits": 224, "unitsPerHectare": 74.67, "lines": [{ "category": "laying-hens", "count": 16000, "coefficient": 0.014, "livestockUnits": 224 }] } },
  { "name": "piglets at 0.027 LU each", "args": ["eurostat", [{ "category": "piglets-under-20kg", "count": 1000 }], 10], "expect": { "livestockUnits": 27, "unitsPerHectare": 2.7, "lines": [{ "category": "piglets-under-20kg", "count": 1000, "coefficient": 0.027, "livestockUnits": 27 }] } },
  { "name": "3 yearlings on 12 ha is 0.175, rounded up to 0.18, where float coefficients say 0.17", "args": ["eurostat", [{ "category": "bovine-1-to-2-years", "count": 3 }], 12], "expect": { "livestockUnits": 2.1, "unitsPerHectare": 0.18, "lines": [{ "category": "bovine-1-to-2-years", "count": 3, "coefficient": 0.7, "livestockUnits": 2.1 }] } },
  { "name": "horses and ponies under Countryside Stewardship", "args": ["uk-countryside-stewardship", [{ "category": "horse", "count": 2 }, { "category": "pony", "count": 3 }], 5.5], "expect": { "livestockUnits": 4.4, "unitsPerHectare": 0.8, "lines": [{ "category": "horse", "count": 2, "coefficient": 1, "livestockUnits": 2 }, { "category": "pony", "count": 3, "coefficient": 0.8, "livestockUnits": 2.4 }] } },
  { "name": "the two tables differ: a goat is 0.1 LU in Eurostat, 0.12 in Countryside Stewardship", "args": ["eurostat", [{ "category": "goats", "count": 50 }], 10], "expect": { "livestockUnits": 5, "unitsPerHectare": 0.5, "lines": [{ "category": "goats", "count": 50, "coefficient": 0.1, "livestockUnits": 5 }] } },
  { "name": "hill ewes on rough grazing, a rate below 0.005 rounds to zero", "args": ["uk-countryside-stewardship", [{ "category": "hill-ewe-and-lamb", "count": 5 }], 100], "expect": { "livestockUnits": 0.4, "unitsPerHectare": 0, "lines": [{ "category": "hill-ewe-and-lamb", "count": 5, "coefficient": 0.08, "livestockUnits": 0.4 }] } },
  { "name": "no animals is zero", "args": ["eurostat", [], 10], "expect": { "livestockUnits": 0, "unitsPerHectare": 0, "lines": [] } },
  { "name": "a count of zero keeps its line", "args": ["eurostat", [{ "category": "sheep", "count": 0 }], 1], "expect": { "livestockUnits": 0, "unitsPerHectare": 0, "lines": [{ "category": "sheep", "count": 0, "coefficient": 0.1, "livestockUnits": 0 }] } },
  { "name": "the smallest area, one square metre", "args": ["eurostat", [{ "category": "sheep", "count": 1 }], 0.0001], "expect": { "livestockUnits": 0.1, "unitsPerHectare": 1000, "lines": [{ "category": "sheep", "count": 1, "coefficient": 0.1, "livestockUnits": 0.1 }] } },
  { "name": "an unknown scheme is an error", "args": ["defra", [], 10], "expectError": "unknown scheme \"defra\"" },
  { "name": "a category from the other table is an error", "args": ["eurostat", [{ "category": "lowland-ewe-and-lamb", "count": 10 }], 10], "expectError": "unknown category \"lowland-ewe-and-lamb\" in scheme eurostat" },
  { "name": "a negative count is an error", "args": ["eurostat", [{ "category": "sheep", "count": -1 }], 10], "expectError": "animal 1: count must be a whole number from 0 to 10000000" },
  { "name": "a fractional count is an error", "args": ["eurostat", [{ "category": "sheep", "count": 2.5 }], 10], "expectError": "animal 1: count must be a whole number from 0 to 10000000" },
  { "name": "zero area is an error", "args": ["eurostat", [], 0], "expectError": "areaHectares must be a finite number greater than 0" },
  { "name": "an area below a square metre is an error", "args": ["eurostat", [], 0.00001], "expectError": "areaHectares must be at least 0.0001 hectares" }
]