Skip to content

Commit

Permalink
Add more tests for Channel Code
Browse files Browse the repository at this point in the history
  • Loading branch information
gredler committed Jul 16, 2022
1 parent bc1431e commit 82861e3
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/main/java/uk/org/okapibarcode/backend/ChannelCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class ChannelCode extends Symbol {

private int[] space = new int[11];
private int[] bar = new int[11];
private double currentValue;
private double targetValue;
private int currentValue;
private int targetValue;

/**
* Sets the preferred number of channels used to encode data. This setting will be
Expand All @@ -39,7 +39,7 @@ public class ChannelCode extends Symbol {
*/
public void setPreferredNumberOfChannels(int channels) {
if (channels < 3 || channels > 8) {
throw new IllegalArgumentException("Invalid Channel Code number of channels: " + channels);
throw new IllegalArgumentException("Invalid number of channels: " + channels);
}
preferredNumberOfChannels = channels;
}
Expand All @@ -56,26 +56,16 @@ public int getPreferredNumberOfChannels() {
@Override
protected void encode() {

int channels;
int i;
int leadingZeroCount;

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

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

if (preferredNumberOfChannels <= 2 || preferredNumberOfChannels > 8) {
channels = 3;
} else {
channels = preferredNumberOfChannels;
throw new OkapiException("Invalid characters in data");
}

int channels = preferredNumberOfChannels;
targetValue = Integer.parseInt(content);

switch (channels) {
case 3:
if (targetValue > 26) {
Expand Down Expand Up @@ -109,7 +99,7 @@ protected void encode() {

infoLine("Channels Used: " + channels);

for (i = 0; i < 11; i++) {
for (int i = 0; i < 11; i++) {
bar[i] = 0;
space[i] = 0;
}
Expand All @@ -119,14 +109,14 @@ protected void encode() {
pattern = new String[1];
nextSpace(channels, 3, channels, channels);

leadingZeroCount = channels - 1 - content.length();

readable = "";
for (i = 0; i < leadingZeroCount; i++) {
readable += "0";
StringBuilder text = new StringBuilder();
int leadingZeroCount = channels - 1 - content.length();
for (int i = 0; i < leadingZeroCount; i++) {
text.append('0');
}
readable += content;
text.append(content);

readable = text.toString();
row_count = 1;
row_height = new int[] { -1 };
}
Expand Down
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,12 @@
PROPERTIES

preferredNumberOfChannels=3
content=27

LOG

Channels Used: 4

CODEWORDS

111100111111221212300000000
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,12 @@
PROPERTIES

preferredNumberOfChannels=3
content=576689

LOG

Channels Used: 8

CODEWORDS

111100111111213211212213143
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,12 @@
PROPERTIES

preferredNumberOfChannels=4
content=293

LOG

Channels Used: 5

CODEWORDS

111100111111214311131000000
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,12 @@
PROPERTIES

preferredNumberOfChannels=5
content=3494

LOG

Channels Used: 6

CODEWORDS

111100111111213411232110000
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,12 @@
PROPERTIES

preferredNumberOfChannels=6
content=44073

LOG

Channels Used: 7

CODEWORDS

111100111111213223142111200
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,12 @@
PROPERTIES

preferredNumberOfChannels=7
content=576689

LOG

Channels Used: 8

CODEWORDS

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

content=1.2

ERROR

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

preferredNumberOfChannels=2
content=7742862

ERROR

Invalid number of channels: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PROPERTIES

content=12345678

ERROR

Input data too long
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PROPERTIES

preferredNumberOfChannels=9
content=7742862

ERROR

Invalid number of channels: 9

0 comments on commit 82861e3

Please sign in to comment.