Functional Weave
Code in Python

validation.luhn@1.0.0

vectors.json

1,794 bytes · view raw

[
  { "name": "the published Luhn worked example 79927398713", "args": ["79927398713"], "expect": true },
  { "name": "the same example with its last digit wrong", "args": ["79927398710"], "expect": false },
  { "name": "a Visa test card number", "args": ["4242424242424242"], "expect": true },
  { "name": "the same card printed in four-digit groups", "args": ["4242 4242 4242 4242"], "expect": true },
  { "name": "the same card hyphenated", "args": ["4242-4242-4242-4242"], "expect": true },
  { "name": "a Mastercard test card number", "args": ["5555555555554444"], "expect": true },
  { "name": "an American Express test card number, fifteen digits", "args": ["378282246310005"], "expect": true },
  { "name": "a published IMEI, so Luhn is not only about cards", "args": ["490154203237518"], "expect": true },
  { "name": "right length, last digit off by one", "args": ["4242424242424241"], "expect": false },
  { "name": "two adjacent digits transposed", "args": ["378282246310050"], "expect": false },
  { "name": "the empty string is not a number", "args": [""], "expect": false },
  { "name": "separators with no digits between them", "args": ["  -  "], "expect": false },
  { "name": "a single zero satisfies the arithmetic but is refused", "args": ["0"], "expect": false },
  { "name": "two digits is the shortest accepted input", "args": ["00"], "expect": true },
  { "name": "underscore is not an accepted separator", "args": ["4242_4242_4242_4242"], "expect": false },
  { "name": "a letter anywhere fails", "args": ["4242 4242 4242 424X"], "expect": false },
  { "name": "leading and trailing spaces are ignored like any other separator", "args": [" 4111 1111 1111 1111 "], "expect": true },
  { "name": "a non-string argument is not a number", "args": [42], "expect": false }
]