Wednesday, October 10, 2012

SOFT6008 Checksum Shopping List

Here's a list of checksum exercises that students should work though:


Euro Banknotes
Credit Card
EAN
PPS Number
Spanish DNI
ISBN-10



Some test cases

IE-PPSN

These numbers are valid in theory
5313197L
1234567T
1234567t
0000000W
0000071w

ES-DNI

These are valid numbers
03457393-X
03457393X
03457393x
03405999-K
70240341-C
70259948-P
70259948p

If these test cases give you trouble read the small print on the ParseInt box!.

I have noticed that in real life Spaniards tend to insert separators between groups of digits to make the DNI number easier to read and it is common to put a dash before the letter (as above). To accommodate this your code should strip out all useless characters from the input before looking at it more closely.

Ensure that your code insists on the correct length
007-X is not valid. But 00000000-X is.

Euro Banknotes

Just take some from your wallet. There are fewer than 26 countries that issue Euro banknotes some some letters never appear at the start of a serial number. Accounting for this would require some very inelegant code. We can't have inelegant code!

Be sure to check some serial numbers that have a zero immediately after the letter. If that gives you trouble ParseInt may be to blame.

1 comment:

Colin Manning said...

Actually 00000000X is not valid