Functional Weave
Code in Rust

validation.uk-modulus-table@1.0.0

vectors.json

8,305 bytes · view raw

[
  {"name": "one line with no exception, and no SCSUBTAB.txt", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1\n", ""], "expect": {"rows": [{"start": "110000", "end": "119999", "algorithm": "MOD10", "weights": [0, 0, 0, 0, 0, 0, 7, 1, 3, 7, 1, 3, 7, 1], "exception": null}], "substitutions": []}},
  {"name": "two rows for one range keep file order: the MOD11 row is the first check", "args": ["140000 149999 MOD11    0    0    0    0    0    0    8    7    6    5    4    3    2    1\n140000 149999 DBLAL    2    1    2    1    2    1    2    1    2    1    2    1    2    1\n", ""], "expect": {"rows": [{"start": "140000", "end": "149999", "algorithm": "MOD11", "weights": [0, 0, 0, 0, 0, 0, 8, 7, 6, 5, 4, 3, 2, 1], "exception": null}, {"start": "140000", "end": "149999", "algorithm": "DBLAL", "weights": [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1], "exception": null}], "substitutions": []}},
  {"name": "a trailing exception column is read as a number", "args": ["210000 210099 DBLAL    2    1    2    1    2    1    2    1    2    1    2    1    2    1    1\n", ""], "expect": {"rows": [{"start": "210000", "end": "210099", "algorithm": "DBLAL", "weights": [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1], "exception": 1}], "substitutions": []}},
  {"name": "Windows line endings read the same as Unix ones", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1\r\n210000 210099 DBLAL    2    1    2    1    2    1    2    1    2    1    2    1    2    1    1\r\n", ""], "expect": {"rows": [{"start": "110000", "end": "119999", "algorithm": "MOD10", "weights": [0, 0, 0, 0, 0, 0, 7, 1, 3, 7, 1, 3, 7, 1], "exception": null}, {"start": "210000", "end": "210099", "algorithm": "DBLAL", "weights": [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1], "exception": 1}], "substitutions": []}},
  {"name": "tabs and single spaces separate fields as well as padding does; blank lines are skipped", "args": ["\n110000\t119999\tMOD10\t0\t0\t0\t0\t0\t0\t7\t1\t3\t7\t1\t3\t7\t1\n\n   \n210000 210099 DBLAL 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1", ""], "expect": {"rows": [{"start": "110000", "end": "119999", "algorithm": "MOD10", "weights": [0, 0, 0, 0, 0, 0, 7, 1, 3, 7, 1, 3, 7, 1], "exception": null}, {"start": "210000", "end": "210099", "algorithm": "DBLAL", "weights": [2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1], "exception": 1}], "substitutions": []}},
  {"name": "a negative weight is kept in a MOD11 row", "args": ["330000 330099 MOD11    0    0    0    0    0    0   -1    7    6    5    4    3    2    1\n", ""], "expect": {"rows": [{"start": "330000", "end": "330099", "algorithm": "MOD11", "weights": [0, 0, 0, 0, 0, 0, -1, 7, 6, 5, 4, 3, 2, 1], "exception": null}], "substitutions": []}},
  {"name": "a range of one sort code, two-digit exception 14, and an exception written 05", "args": ["320040 320040 MOD11    0    0    0    0    0    0    8    7    6    5    4    3    2    1   14\n250000 250099 MOD11    7    6    5    4    3    2    7    6    5    4    3    2    0    0   05\n", ""], "expect": {"rows": [{"start": "320040", "end": "320040", "algorithm": "MOD11", "weights": [0, 0, 0, 0, 0, 0, 8, 7, 6, 5, 4, 3, 2, 1], "exception": 14}, {"start": "250000", "end": "250099", "algorithm": "MOD11", "weights": [7, 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 0, 0], "exception": 5}], "substitutions": []}},
  {"name": "SCSUBTAB.txt lines become substitutions, in order", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1\n", "250050 250010\r\n250051   250020\r\n"], "expect": {"rows": [{"start": "110000", "end": "119999", "algorithm": "MOD10", "weights": [0, 0, 0, 0, 0, 0, 7, 1, 3, 7, 1, 3, 7, 1], "exception": null}], "substitutions": [{"original": "250050", "substitute": "250010"}, {"original": "250051", "substitute": "250020"}]}},
  {"name": "a byte order mark at the start of the file is ignored", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1", "250050 250010"], "expect": {"rows": [{"start": "110000", "end": "119999", "algorithm": "MOD10", "weights": [0, 0, 0, 0, 0, 0, 7, 1, 3, 7, 1, 3, 7, 1], "exception": null}], "substitutions": [{"original": "250050", "substitute": "250010"}]}},
  {"name": "a double-digit weight", "args": ["400000 400099 MOD11    0    0    0    0    0    0   10    9    8    7    6    5    4    3\n", ""], "expect": {"rows": [{"start": "400000", "end": "400099", "algorithm": "MOD11", "weights": [0, 0, 0, 0, 0, 0, 10, 9, 8, 7, 6, 5, 4, 3], "exception": null}], "substitutions": []}},
  {"name": "a line with only 13 weights", "args": ["110000 119999 MOD10 0 0 0 0 0 0 7 1 3 7 1 3 7\n", ""], "expectError": "VALACDOS.txt line 1: expected 17 or 18 fields (start, end, algorithm, 14 weights, optional exception), found 16"},
  {"name": "a line with a nineteenth field", "args": ["110000 119999 MOD10 0 0 0 0 0 0 7 1 3 7 1 3 7 1 1 1\n", ""], "expectError": "VALACDOS.txt line 1: expected 17 or 18 fields"},
  {"name": "line numbers count blank lines, so the error points at the right line", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1\n\n110000 119999 MOD10 0 0 0\n", ""], "expectError": "VALACDOS.txt line 3: expected 17 or 18 fields"},
  {"name": "a letter in a sort code", "args": ["11000A 119999 MOD10 0 0 0 0 0 0 7 1 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: \"11000A\" is not a six-digit sort code"},
  {"name": "non-ASCII digits are not a sort code", "args": ["١١0000 119999 MOD10 0 0 0 0 0 0 7 1 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: \"١١0000\" is not a six-digit sort code"},
  {"name": "a five-digit end of range", "args": ["110000 11999 MOD10 0 0 0 0 0 0 7 1 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: \"11999\" is not a six-digit sort code"},
  {"name": "a range that ends before it starts", "args": ["119999 110000 MOD10 0 0 0 0 0 0 7 1 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: range 119999 to 110000 ends before it starts"},
  {"name": "algorithm names are upper case", "args": ["110000 119999 mod10 0 0 0 0 0 0 7 1 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: unknown algorithm \"mod10\"; expected MOD10, MOD11 or DBLAL"},
  {"name": "a fractional weight", "args": ["110000 119999 MOD10 0 0 0 0 0 0 7 1.5 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: weight \"1.5\" is not a whole number"},
  {"name": "a weight with a plus sign", "args": ["110000 119999 MOD10 0 0 0 0 0 0 7 +1 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: weight \"+1\" is not a whole number"},
  {"name": "a five-digit weight", "args": ["110000 119999 MOD10 0 0 0 0 0 0 7 10000 3 7 1 3 7 1", ""], "expectError": "VALACDOS.txt line 1: weight \"10000\" is not a whole number"},
  {"name": "a negative weight in a DBLAL row", "args": ["140000 149999 DBLAL 2 1 2 1 2 1 2 -1 2 1 2 1 2 1", ""], "expectError": "VALACDOS.txt line 1: a DBLAL row cannot have a negative weight"},
  {"name": "exception 15 does not exist", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1 15", ""], "expectError": "VALACDOS.txt line 1: exception \"15\" is not a number from 1 to 14"},
  {"name": "exception 0 does not exist", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1 0", ""], "expectError": "VALACDOS.txt line 1: exception \"0\" is not a number from 1 to 14"},
  {"name": "an empty VALACDOS.txt would leave every sort code unchecked", "args": ["", ""], "expectError": "VALACDOS.txt has no rows"},
  {"name": "a file of blank lines has no rows either", "args": ["\r\n  \r\n", ""], "expectError": "VALACDOS.txt has no rows"},
  {"name": "an SCSUBTAB.txt line with three fields", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1", "250050 250010 250020"], "expectError": "SCSUBTAB.txt line 1: expected two sort codes, found 3 fields"},
  {"name": "an SCSUBTAB.txt line with a short sort code, on line 2", "args": ["110000 119999 MOD10    0    0    0    0    0    0    7    1    3    7    1    3    7    1", "250050 250010\n25005 250010"], "expectError": "SCSUBTAB.txt line 2: \"25005\" is not a six-digit sort code"}
]