Skip to content

Commit

Permalink
Add digit check to luhn.verify (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iapetus999 authored Aug 7, 2024
1 parent cd3032e commit 88c06cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions larky/src/main/resources/vendor/luhn.star
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def verify(num):
>>> verify('534618613411236')
False
"""
if not isdigit(num):
return False
checksum = int(num[-1])
cardSum = int(_luhn_summation(num,-2))
return ((cardSum + checksum) % 10) == 0
Expand Down
3 changes: 3 additions & 0 deletions larky/src/test/resources/vendor_tests/luhn/luhn_test.star
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def test_valid():
def test_invalid():
asserts.assert_that(luhn.verify('4222222222222222')).is_equal_to(False)

def test_nonumeric():
asserts.assert_that(luhn.verify('422222222x22222')).is_equal_to(False)

def test_generate():
asserts.assert_that(luhn.generate('7992739871')).is_equal_to(3)

Expand Down

0 comments on commit 88c06cf

Please sign in to comment.