| Copyright | (c) N-Sim Ltd. 2008 |
|---|---|
| License | BSD3 |
| Maintainer | jhb@n-sim.com |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Luhn
Description
An implementation of Luhn's check digit algorithm.
Synopsis
- addLuhnDigit :: Integral n => n -> n
- checkLuhnDigit :: Integral n => n -> Bool
- prop_checkLuhn :: Integer -> Property
- prop_checkSingleError :: Integer -> Integer -> Integer -> Property
Creating a check digit
Arguments
| :: Integral n | |
| => n | Number to which a Luhn check digit will be appended. |
| -> n | Number with the appended Luhn check digit. |
Appends a Luhn check digit to the end of a number.
Validating a check digit
Arguments
| :: Integral n | |
| => n | Number with a Luhn check digit as its last digit. |
| -> Bool | Whether or not the check digit is consistent. |
Validates that the Luhn check digit (assumed to be the last/least- significant digit in the number) is correct.
QuickCheck tests
Validates that a generated check digit validates.
prop_checkSingleError Source #
Arguments
| :: Integer | The number to transcribe. |
| -> Integer | The position to introduce a transcription error. |
| -> Integer | The number to transcribe in place of the original. |
| -> Property |
Any single number transcription error should result in a failure in the validation of a Luhn check digit. This property validates this.