Skip to content

Commit

Permalink
Add more tests for KoreaPost
Browse files Browse the repository at this point in the history
  • Loading branch information
gredler committed Jul 15, 2022
1 parent 4c6d50f commit bc1431e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/uk/org/okapibarcode/backend/KoreaPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public class KoreaPost extends Symbol {
protected void encode() {

if (!content.matches("[0-9]+")) {
throw new OkapiException("Invalid characters in input");
throw new OkapiException("Invalid characters in data");
}

if (content.length() > 6) {
throw new OkapiException("Input data too long");
}

String padded = "";
for (int i = 0; i < (6 - content.length()); i++) {
padded += "0";
StringBuilder padded = new StringBuilder(6);
for (int i = content.length(); i < 6; i++) {
padded.append('0');
}
padded += content;
padded.append(content);

int total = 0;
String accumulator = "";
Expand All @@ -53,16 +53,17 @@ protected void encode() {
total += j;
}

int checkd = 10 - (total % 10);
if (checkd == 10) {
checkd = 0;
int check = 10 - (total % 10);
if (check == 10) {
check = 0;
}
infoLine("Check Digit: " + checkd);
accumulator += KOREA_TABLE[checkd];
accumulator += KOREA_TABLE[check];
infoLine("Check Digit: " + check);

readable = padded + checkd;
readable = padded.toString() + check;
pattern = new String[] { accumulator };
row_count = 1;
row_height = new int[] { -1 };
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PROPERTIES

content=984766

LOG

Check Digit: 0

CODEWORDS

131717131713171304131713130413131713131506131313150613131313150613
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PROPERTIES

content=1A2

ERROR

Invalid characters in data
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PROPERTIES

content=1234567

ERROR

Input data too long

0 comments on commit bc1431e

Please sign in to comment.