Skip to content

Lunh Test Kata in clojure - using RDD and going a bit extreme on threading ;)

Notifications You must be signed in to change notification settings

rojoangel/lunh-test-kata-clojure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Luhn test

The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Take the first, third, ... and every other odd digit in the reversed digits and sum them to form the partial sum s1 Taking the second, fourth ... and every other even digit in the reversed digits: Multiply each digit by two and sum the digits if the answer is greater than nine to form partial sums for the even digits Sum the partial sums of the even digits to form s2 If s1 + s2 ends in zero then the original number is in the form of a valid credit card number as verified by the Luhn test. For example, if the trial number is 49927398716:

Reverse the digits:

>    61789372994
> Sum the odd digits:
>    6 + 7 + 9 + 7 + 9 + 4 = 42 = s1
>    The even digits:
>    1,  8,  3,  2,  9
>    Two times each even digit:
>    2, 16,  6,  4, 18
>      Sum the digits of each multiplication:
>    2,  7,  6,  4,  9
>      Sum the last:
>    2 + 7 + 6 + 4 + 9 = 28 = s2

s1 + s2 = 70 which ends in zero which means that 49927398716 passes the Luhn test

Taken from https://github.com/trikitrok/Katas/blob/master/2015-01-LuhnTest/readme.md

The project uses Midje.

How to run the tests

lein midje will run all tests.

lein midje namespace.* will run only tests beginning with "namespace.".

lein midje :autotest will run all the tests indefinitely. It sets up a watcher on the code files. If they change, only the relevant tests will be run again.

About

Lunh Test Kata in clojure - using RDD and going a bit extreme on threading ;)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published