luhn.test.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { valid } from './luhn'
  2. xit = it
  3. describe('Luhn', () => {
  4. it('single digit strings can not be valid', () => {
  5. expect(valid('1')).toBeFalsy()
  6. })
  7. xit('a single zero is invalid', () => {
  8. expect(valid('0')).toBeFalsy()
  9. })
  10. xit('a simple valid SIN that remains valid if reversed', () => {
  11. expect(valid('059')).toBeTruthy()
  12. })
  13. xit('a simple valid SIN that becomes invalid if reversed', () => {
  14. expect(valid('59')).toBeTruthy()
  15. })
  16. xit('a valid Canadian SIN', () => {
  17. expect(valid('055 444 285')).toBeTruthy()
  18. })
  19. xit('invalid Canadian SIN', () => {
  20. expect(valid('055 444 286')).toBeFalsy()
  21. })
  22. xit('invalid credit card', () => {
  23. expect(valid('8273 1232 7352 0569')).toBeFalsy()
  24. })
  25. xit('invalid long number with an even remainder', () => {
  26. expect(valid('1 2345 6789 1234 5678 9012')).toBeFalsy()
  27. })
  28. xit('invalid long number with a remainder divisible by 5', () => {
  29. expect(valid('1 2345 6789 1234 5678 9013')).toBeFalsy()
  30. })
  31. xit('valid number with an even number of digits', () => {
  32. expect(valid('095 245 88')).toBeTruthy()
  33. })
  34. xit('valid number with an odd number of spaces', () => {
  35. expect(valid('234 567 891 234')).toBeTruthy()
  36. })
  37. xit('valid strings with a non-digit added at the end become invalid', () => {
  38. expect(valid('059a')).toBeFalsy()
  39. })
  40. xit('valid strings with punctuation included become invalid', () => {
  41. expect(valid('055-444-285')).toBeFalsy()
  42. })
  43. xit('valid strings with symbols included become invalid', () => {
  44. expect(valid('055# 444$ 285')).toBeFalsy()
  45. })
  46. xit('single zero with space is invalid', () => {
  47. expect(valid(' 0')).toBeFalsy()
  48. })
  49. xit('more than a single zero is valid', () => {
  50. expect(valid('0000 0')).toBeTruthy()
  51. })
  52. xit('input digit 9 is correctly converted to output digit 9', () => {
  53. expect(valid('091')).toBeTruthy()
  54. })
  55. xit('very long input is valid', () => {
  56. expect(valid('9999999999 9999999999 9999999999 9999999999')).toBeTruthy()
  57. })
  58. xit('valid luhn with an odd number of digits and non zero first digit', () => {
  59. expect(valid('109')).toBeTruthy()
  60. })
  61. xit("using ascii value for non-doubled non-digit isn't allowed", () => {
  62. expect(valid('055b 444 285')).toBeFalsy()
  63. })
  64. xit("using ascii value for doubled non-digit isn't allowed", () => {
  65. expect(valid(':9')).toBeFalsy()
  66. })
  67. xit("non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed", () => {
  68. expect(valid('59%59')).toBeFalsy()
  69. })
  70. })