Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update luhn tests to newest canonical data #120

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 55 additions & 31 deletions exercises/luhn/luhn.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,70 @@ Luhn = require './luhn'

describe 'Luhn', ->

it "check digit", ->
luhn = new Luhn(34567)
expect(luhn.checkDigit).toEqual(7)
it 'single digit strings can not be valid', ->
luhn = new Luhn('1')
expect(luhn.valid).toEqual(false)

xit "check digit again", ->
luhn = new Luhn(91370)
expect(luhn.checkDigit).toEqual(0)
xit 'a single zero is invalid', ->
luhn = new Luhn('0')
expect(luhn.valid).toEqual(false)

xit "addends", ->
luhn = new Luhn(12121)
expect(luhn.addends).toEqual([1, 4, 1, 4, 1])
xit 'a simple valid SIN that remains valid if reversed', ->
luhn = new Luhn('059')
expect(luhn.valid).toEqual(true)

xit "too large added", ->
luhn = new Luhn(8631)
expect(luhn.addends).toEqual([7, 6, 6, 1])
xit 'a simple valid SIN that becomes invalid if reversed', ->
luhn = new Luhn('59')
expect(luhn.valid).toEqual(true)

xit "checksum", ->
luhn = new Luhn(4913)
expect(luhn.checksum).toEqual(22)
xit 'a valid Canadian SIN', ->
luhn = new Luhn('055 444 286')
expect(luhn.valid).toEqual(true)

xit "checksum again", ->
luhn = new Luhn(201773)
expect(luhn.checksum).toEqual(21)
xit 'invalid credit card', ->
luhn = new Luhn('8273 1232 7352 0569')
expect(luhn.valid).toEqual(false)

xit "invalid number", ->
luhn = new Luhn(738)
xit 'invalid credit card', ->
luhn = new Luhn('8273 1232 7352 0569')
expect(luhn.valid).toEqual(false)

xit "valid number", ->
luhn = new Luhn(8739567)
xit 'valid number with an even number of digits', ->
luhn = new Luhn('095 245 88')
expect(luhn.valid).toEqual(true)

xit "create valid number", ->
number = Luhn.create(123)
expect(number).toEqual(1230)
xit 'valid number with an odd number of spaces', ->
luhn = new Luhn('234 567 891 234')
expect(luhn.valid).toEqual(true)

xit "create other valid number", ->
number = Luhn.create(873956)
expect(number).toEqual(8739567)
xit 'valid strings with a non-digit added at the end become invalid', ->
luhn = new Luhn('059a')
expect(luhn.valid).toEqual(false)

xit "create yet another valid number", ->
number = Luhn.create(837263756)
expect(number).toEqual(8372637564)
xit 'valid strings with punctuation included become invalid', ->
luhn = new Luhn('055-444-285')
expect(luhn.valid).toEqual(false)

xit 'valid strings with symbols included become invalid', ->
luhn = new Luhn('055# 444$ 285')
expect(luhn.valid).toEqual(false)

xit 'single zero with space is invalid', ->
luhn = new Luhn(' 0')
expect(luhn.valid).toEqual(false)

xit 'more than a single zero is valid', ->
luhn = new Luhn('0000 0')
expect(luhn.valid).toEqual(true)

xit 'input digit 9 is correctly converted to output digit 9', ->
luhn = new Luhn('091')
expect(luhn.valid).toEqual(true)

xit 'using ascii value for non-doubled non-digit isn\'t allowed', ->
luhn = new Luhn('055b 444 285')
expect(luhn.valid).toEqual(false)

xit 'using ascii value for non-doubled non-digit isn\'t allowed', ->
luhn = new Luhn(':9')
expect(luhn.valid).toEqual(false)