Skip to content

Commit

Permalink
Greek VATIN Testcase wich results to checkdigit 10 == 'X'
Browse files Browse the repository at this point in the history
  • Loading branch information
homebeaver committed Oct 19, 2024
1 parent 8eec607 commit 251d8e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public String calculate(final String code) throws CheckDigitException {
if (GenericTypeValidator.formatLong(code) == 0) {
throw new CheckDigitException(CheckDigitException.ZERO_SUM);
}

return toCheckDigit(INSTANCE.calculateModulus(code, false));
final int cm = INSTANCE.calculateModulus(code, false);
return toCheckDigit(cm > 9 ? 0 : cm); // CHECKSTYLE IGNORE MagicNumber
}

/**
Expand All @@ -100,8 +100,11 @@ public boolean isValid(final String code) {
if (GenericTypeValidator.formatLong(code.substring(0, code.length() - 1)) == 0) {
throw new CheckDigitException(CheckDigitException.ZERO_SUM);
}
final int modulusResult = INSTANCE.calculateModulus(code, true);
return modulusResult == Character.getNumericValue(code.charAt(code.length() - 1));
int cm = INSTANCE.calculateModulus(code, true);
if (cm > 9) { // CHECKSTYLE IGNORE MagicNumber
cm = 0;
}
return cm == Character.getNumericValue(code.charAt(code.length() - 1));
} catch (final CheckDigitException ex) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ protected void setUp() {
valid = new String[] {"040127797"
, "023456780", "094259216"
, "998537832", "094327684"
, "000000130"
};
invalid = new String[] {"123456781"}; // PZ nuss 3 sein
invalid = new String[] {"123456781"}; // check digit expected 3
}

}

0 comments on commit 251d8e0

Please sign in to comment.