Hi,
For CheckLuhnMod10.java I found that only some check digits were verified
correctly. When the amount of digits is odd verify would return false
incorrectly. An even amount of digits will work.
The reason is that the computeSum function does not strip the checkdigit
before calculating the Luhn value.
The JUnit test will not notice this since the cases are all an even 10
digits long.
In the method verify(String digits)
I used:
return (((computeSum(getData(digits)) + getCheckDigit(digits)) % 10) == 0);
instead of:
return ((computeSum(digits) % 10) == 0);
Which worked for my test code
CheckLuhnMod10 clm = new CheckLuhnMod10();
for (Long x=0L; x <= 20000L ; x++) {
String raw = x.toString()+"";
String cb = clm.computeCheck(raw)+"";
// print all instances where the verify returns false
if (!clm.verify(raw + cb)) System.out.println("["+raw+"|"+cb+"]");
}
p.s. I like your coding style
Original issue reported on code.google.com by
[email protected]on 26 Mar 2008 at 1:06