Functional Weave
Code in Rust

property.service-charge-apportion@1.0.1

vectors.json

9,079 bytes · view raw

[
 {
  "name": "£10,000 in thirds: the odd penny goes to the first flat",
  "args": [
   {
    "minor": 1000000,
    "currency": "GBP"
   },
   [
    {
     "unit": "Flat 1",
     "share": 1,
     "of": 3
    },
    {
     "unit": "Flat 2",
     "share": 1,
     "of": 3
    },
    {
     "unit": "Flat 3",
     "share": 1,
     "of": 3
    }
   ],
   "fraction"
  ],
  "expect": [
   {
    "unit": "Flat 1",
    "charge": {
     "minor": 333334,
     "currency": "GBP"
    }
   },
   {
    "unit": "Flat 2",
    "charge": {
     "minor": 333333,
     "currency": "GBP"
    }
   },
   {
    "unit": "Flat 3",
    "charge": {
     "minor": 333333,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "1/3, 1/6, 1/2 of £100.01: £33.34, £16.67, £50.00, not £100.02 by separate rounding",
  "args": [
   {
    "minor": 10001,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 1,
     "of": 3
    },
    {
     "unit": "B",
     "share": 1,
     "of": 6
    },
    {
     "unit": "C",
     "share": 1,
     "of": 2
    }
   ],
   "fraction"
  ],
  "expect": [
   {
    "unit": "A",
    "charge": {
     "minor": 3334,
     "currency": "GBP"
    }
   },
   {
    "unit": "B",
    "charge": {
     "minor": 1667,
     "currency": "GBP"
    }
   },
   {
    "unit": "C",
    "charge": {
     "minor": 5000,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "a half and two quarters",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "Shop",
     "share": 1,
     "of": 2
    },
    {
     "unit": "Flat A",
     "share": 1,
     "of": 4
    },
    {
     "unit": "Flat B",
     "share": 1,
     "of": 4
    }
   ],
   "fraction"
  ],
  "expect": [
   {
    "unit": "Shop",
    "charge": {
     "minor": 5000,
     "currency": "GBP"
    }
   },
   {
    "unit": "Flat A",
    "charge": {
     "minor": 2500,
     "currency": "GBP"
    }
   },
   {
    "unit": "Flat B",
    "charge": {
     "minor": 2500,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "twentieths and quarters mixed: 3/20, 7/20, 1/4, 1/4 of £4,000",
  "args": [
   {
    "minor": 400000,
    "currency": "GBP"
   },
   [
    {
     "unit": "1",
     "share": 3,
     "of": 20
    },
    {
     "unit": "2",
     "share": 7,
     "of": 20
    },
    {
     "unit": "3",
     "share": 1,
     "of": 4
    },
    {
     "unit": "4",
     "share": 1,
     "of": 4
    }
   ],
   "fraction"
  ],
  "expect": [
   {
    "unit": "1",
    "charge": {
     "minor": 60000,
     "currency": "GBP"
    }
   },
   {
    "unit": "2",
    "charge": {
     "minor": 140000,
     "currency": "GBP"
    }
   },
   {
    "unit": "3",
    "charge": {
     "minor": 100000,
     "currency": "GBP"
    }
   },
   {
    "unit": "4",
    "charge": {
     "minor": 100000,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "floor areas 50, 70 and 80 m² share £1,000",
  "args": [
   {
    "minor": 100000,
    "currency": "GBP"
   },
   [
    {
     "unit": "G",
     "share": 50,
     "of": null
    },
    {
     "unit": "1",
     "share": 70,
     "of": null
    },
    {
     "unit": "2",
     "share": 80,
     "of": null
    }
   ],
   "floor-area"
  ],
  "expect": [
   {
    "unit": "G",
    "charge": {
     "minor": 25000,
     "currency": "GBP"
    }
   },
   {
    "unit": "1",
    "charge": {
     "minor": 35000,
     "currency": "GBP"
    }
   },
   {
    "unit": "2",
    "charge": {
     "minor": 40000,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "areas in hundredths of a m²: the spare penny goes to the largest remainder",
  "args": [
   {
    "minor": 234567,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 5525,
     "of": null
    },
    {
     "unit": "B",
     "share": 7250,
     "of": null
    },
    {
     "unit": "C",
     "share": 4725,
     "of": null
    }
   ],
   "floor-area"
  ],
  "expect": [
   {
    "unit": "A",
    "charge": {
     "minor": 74056,
     "currency": "GBP"
    }
   },
   {
    "unit": "B",
    "charge": {
     "minor": 97178,
     "currency": "GBP"
    }
   },
   {
    "unit": "C",
    "charge": {
     "minor": 63333,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "fixed percentages 33.33%, 33.33%, 33.34% of £100",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "1",
     "share": 3333,
     "of": null
    },
    {
     "unit": "2",
     "share": 3333,
     "of": null
    },
    {
     "unit": "3",
     "share": 3334,
     "of": null
    }
   ],
   "percentage"
  ],
  "expect": [
   {
    "unit": "1",
    "charge": {
     "minor": 3333,
     "currency": "GBP"
    }
   },
   {
    "unit": "2",
    "charge": {
     "minor": 3333,
     "currency": "GBP"
    }
   },
   {
    "unit": "3",
    "charge": {
     "minor": 3334,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "a unit with a zero share pays nothing but keeps its line",
  "args": [
   {
    "minor": 50000,
    "currency": "GBP"
   },
   [
    {
     "unit": "Flat",
     "share": 100,
     "of": null
    },
    {
     "unit": "Car port",
     "share": 0,
     "of": null
    }
   ],
   "floor-area"
  ],
  "expect": [
   {
    "unit": "Flat",
    "charge": {
     "minor": 50000,
     "currency": "GBP"
    }
   },
   {
    "unit": "Car port",
    "charge": {
     "minor": 0,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "a surplus is shared out the same way",
  "args": [
   {
    "minor": -10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 1,
     "of": 3
    },
    {
     "unit": "B",
     "share": 1,
     "of": 3
    },
    {
     "unit": "C",
     "share": 1,
     "of": 3
    }
   ],
   "fraction"
  ],
  "expect": [
   {
    "unit": "A",
    "charge": {
     "minor": -3333,
     "currency": "GBP"
    }
   },
   {
    "unit": "B",
    "charge": {
     "minor": -3333,
     "currency": "GBP"
    }
   },
   {
    "unit": "C",
    "charge": {
     "minor": -3334,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "one unit takes it all",
  "args": [
   {
    "minor": 123456,
    "currency": "GBP"
   },
   [
    {
     "unit": "House",
     "share": 1,
     "of": 1
    }
   ],
   "fraction"
  ],
  "expect": [
   {
    "unit": "House",
    "charge": {
     "minor": 123456,
     "currency": "GBP"
    }
   }
  ]
 },
 {
  "name": "fractions that do not make a whole are refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 1,
     "of": 3
    },
    {
     "unit": "B",
     "share": 1,
     "of": 3
    }
   ],
   "fraction"
  ],
  "expectError": "the fractions add up to 2/3, not exactly 1"
 },
 {
  "name": "fractions over a whole are refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 1,
     "of": 2
    },
    {
     "unit": "B",
     "share": 2,
     "of": 3
    }
   ],
   "fraction"
  ],
  "expectError": "the fractions add up to 7/6, not exactly 1"
 },
 {
  "name": "percentages short of 100% are refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "1",
     "share": 5000,
     "of": null
    },
    {
     "unit": "2",
     "share": 4999,
     "of": null
    }
   ],
   "percentage"
  ],
  "expectError": "the percentages add up to 9999 basis points, not 10000"
 },
 {
  "name": "a fraction without a denominator is refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 1,
     "of": null
    },
    {
     "unit": "B",
     "share": 1,
     "of": 2
    }
   ],
   "fraction"
  ],
  "expectError": "unit \"A\": a fraction needs a denominator"
 },
 {
  "name": "a denominator on a floor area is refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 50,
     "of": 100
    }
   ],
   "floor-area"
  ],
  "expectError": "unit \"A\": \"of\" is only for the fraction basis"
 },
 {
  "name": "a negative share is refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": -1,
     "of": null
    },
    {
     "unit": "B",
     "share": 101,
     "of": null
    }
   ],
   "floor-area"
  ],
  "expectError": "unit \"A\": share must be a whole number"
 },
 {
  "name": "no units is refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [],
   "floor-area"
  ],
  "expectError": "units must not be empty"
 },
 {
  "name": "all-zero floor areas are refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 0,
     "of": null
    },
    {
     "unit": "B",
     "share": 0,
     "of": null
    }
   ],
   "floor-area"
  ],
  "expectError": "the floor areas add up to zero"
 },
 {
  "name": "an unknown basis is refused",
  "args": [
   {
    "minor": 10000,
    "currency": "GBP"
   },
   [
    {
     "unit": "A",
     "share": 1,
     "of": null
    }
   ],
   "rateable-value"
  ],
  "expectError": "unknown basis"
 }
]