From 82861e38d0e335a9687543242262b6cfbc29b388 Mon Sep 17 00:00:00 2001 From: Daniel Gredler Date: Fri, 15 Jul 2022 20:09:53 -0400 Subject: [PATCH] Add more tests for Channel Code --- .../org/okapibarcode/backend/ChannelCode.java | 36 +++++++----------- .../channelcode/basic-3-channels-to-4.png | Bin 0 -> 886 bytes .../basic-3-channels-to-4.properties | 12 ++++++ .../channelcode/basic-3-channels-to-8.png | Bin 0 -> 1729 bytes .../basic-3-channels-to-8.properties | 12 ++++++ .../channelcode/basic-4-channels-to-5.png | Bin 0 -> 1227 bytes .../basic-4-channels-to-5.properties | 12 ++++++ .../channelcode/basic-5-channels-to-6.png | Bin 0 -> 1356 bytes .../basic-5-channels-to-6.properties | 12 ++++++ .../channelcode/basic-6-channels-to-7.png | Bin 0 -> 1533 bytes .../basic-6-channels-to-7.properties | 12 ++++++ .../channelcode/basic-7-channels-to-8.png | Bin 0 -> 1729 bytes .../basic-7-channels-to-8.properties | 12 ++++++ .../channelcode/invalid-chars.properties | 7 ++++ .../channelcode/too-few-channels.properties | 8 ++++ .../backend/channelcode/too-long.properties | 7 ++++ .../channelcode/too-many-channels.properties | 8 ++++ 17 files changed, 115 insertions(+), 23 deletions(-) create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-4.png create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-4.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-8.png create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-8.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels-to-5.png create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels-to-5.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels-to-6.png create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels-to-6.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels-to-7.png create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels-to-7.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels-to-8.png create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels-to-8.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/invalid-chars.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/too-few-channels.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/too-long.properties create mode 100644 src/test/resources/uk/org/okapibarcode/backend/channelcode/too-many-channels.properties diff --git a/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java b/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java index a2dbd6f8..ef4f27dc 100644 --- a/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java +++ b/src/main/java/uk/org/okapibarcode/backend/ChannelCode.java @@ -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 @@ -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; } @@ -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) { @@ -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; } @@ -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 }; } diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-4.png b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-4.png new file mode 100644 index 0000000000000000000000000000000000000000..6d2907dd5b5bcc0918c2640a6c58faeaf645048d GIT binary patch literal 886 zcmeAS@N?(olHy`uVBq!ia0vp^&lngOziK% z;O_rRU)G7+8hNQz>b&(jsBJB=_b`+NK2^#7SNMgi?ZAo$ETFJ6XIWIk@* zXW9Mp{}ICr2W>Xn_U`<8%SCAO^Obc4PBY_v#vkQ5Gxy9s*I$Kc)tPB~#5eCXG0sap zwt42{<*(n}-1hbBgBO?W@>0*;-Tc-l?Vi2xXA9#`Y73mwmaJ{inmMt`@b%2MQ)f>6 z#uaw5XG?CgSK2+f09E5hZytS@JX68_tm%_dn#(=45?Ny*ZLZSwS0_fwYu#4y)crQq z@cNYP2IAaT-twj8N$%^ioZELIU2jU)vd>k~Np+EDQlE;R`T6GQyfbNjfpxK!%*BfC z(MM$X&aBZizq|SQWB=+YFV9>wxE=MWIy}Qhf7XsEch07-WASwlUL1Jhj*RrZNQ1kl z?npAdkA8FAz+LID^^CP0mLD3AT|M*fe6HAxj|^$6|A=W#tqeST1Qq<*UCXdx|J^%Z S~)y?cAo5(OTH zfPep&-`u`-?b^V}0;0?PwompnegfIJIvai?=neo!AyTZ()$>{R1ER4#o03PUc}g{EWw6LqsA;HX*X@(BlI3!+%nF9tZO@ zTCMz0D13N37jv8Jz6ILxz0pQ%c;nI~gp>_Cr<|22+M0Xai{)YU1nFhoOPpy%NVB<+Wa`UU@M7&%&}lz5Cb?pD{c$UDE5Y?&me1KX~&z{>;-}`;wpUx6J{A z+wU_S^}e4ve`v$`Q;#nkFfdPivD$k75raBj=U-dOQ)WoSrAX|bpO{oJ`QgQtN4|&s zUikdgo9z;9+YSZHIuQ5n|BH7w=g23`_-)X$lzmzA!tcI^&m;+J-!FT9cd2cxm$^vW za>+D#=hO$Pb2jli|C&4RsQTW-hIJpja_S1yFFZAopV{pbUn=wmd&M#^NY8(#qBk| zb>@`)!YPGYC!F7rclc;}pP62EXq5QM8$UE;)Mp3nnDfi#)iKw5Rw7dWE@wu2{VRI4 z`KI)Ao0yql@$W7DWYp$fVlxkyO!MFPUZOX`Vsn<4|6cK()BZetCVy$#vahdZUJaTw zJ-BxFv%aGXr{80m8`}9h=+&i<#j}!dWjgTe~DWM4f D8%2pX literal 0 HcmV?d00001 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-8.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-8.properties new file mode 100644 index 00000000..a9511833 --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-3-channels-to-8.properties @@ -0,0 +1,12 @@ +PROPERTIES + +preferredNumberOfChannels=3 +content=576689 + +LOG + +Channels Used: 8 + +CODEWORDS + +111100111111213211212213143 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels-to-5.png b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels-to-5.png new file mode 100644 index 0000000000000000000000000000000000000000..46676093bb72a3ef12047ca66c1a35151887c76f GIT binary patch literal 1227 zcmeAS@N?(olHy`uVBq!ia0y~yVB`bhFC0JthL@M;urV;OO!9Pb45_&F_Rhh+B?>iAk=XR<6qI^VoWGNz@h(?JpUsQq!-hZSHv}wD!VcRZ}*(r_<9# zv+hK+7j86vdof7LdGEu!^9mlzb;Z0tQMtszO{%th7JvG$l#1FNtHS5rQ!}-z;IWYt zsy;S*L#OhG>i&6|ZOS!=RAtVKS3J1j-#>NIu~a*rYlS{{D(0Wk*=rMZbm3{eCkyo? zj^BSG@!P_(G5O8WDsK0~jm++b#}8fKkkt20R_5eg(Z4x6D!KP(+?H^^edwZ^-T`IH zTUC8aAI^{Ja|uwscIfKCgSIlY200QOo4$RvoaETc;{N`5@s^Yo3a2g#->&QPSyJ+% zGGOAgnu*GiuDrI^ea|J%Y!WG)b8qvOlys@=N3XU7i@HnOUWmP=`R{<;kF_QiERWvl z&8XRJ*_xcU!A<*@h(&AihxdEWA6?GwKKF#7>9^MyCjnVd3*FZ(VkHk>#8?d#PRUCY1Q zJPUrN{(a4y^OwBU>su|Wx)!g0@?z@$=$^&t7Kdyj^gq0KZE0lwp{;XqZOsFRGQmqO wo3nI&ZS#CC{A6XlW^DfUhgh=BNA>OX=P#bKx>p1>boFyt=akR{0G-_eCIA2c literal 0 HcmV?d00001 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels-to-5.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels-to-5.properties new file mode 100644 index 00000000..7bd9fcce --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-4-channels-to-5.properties @@ -0,0 +1,12 @@ +PROPERTIES + +preferredNumberOfChannels=4 +content=293 + +LOG + +Channels Used: 5 + +CODEWORDS + +111100111111214311131000000 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels-to-6.png b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels-to-6.png new file mode 100644 index 0000000000000000000000000000000000000000..7391ef71b9bfec471d129ad08124fc4595e4e96d GIT binary patch literal 1356 zcmeAS@N?(olHy`uVBq!ia0y~yU^D~bFC0JthDqP!PBAdB3VXUZhE&{od*|Y`#R@zO z0ssClzqx#_WqOp3;=!!y$~D(s=r#%DWZN(OKc#m5*}U3q_X|6Z+uEJ_GBfFL8?Urk z&W#O;qm0o&Kurm?lF{K}T;RkJ3{D@jo4{#B1e{!!P1)2s*<5{T^*LXytw)PzTOD@! zr`J~KH^p^Z#4W?QKj*Alc~U|9yYuOlyv(5~J=L$iYxZqACFZPgZcG3EV!tV=+aA0O zT@zrjJZ$^i9RBt?!Ph6Ry?E)W{WZ$_YT2fbt>;rtn+j~ssTIC`hdEs} zT015Cq{jEeYO4%CDXTe7a^=!!q($|>Axo71R~pU(Xx_?KqR-(5KeJ^zXATyQeQ&FEC;jF0F14Zacd^6NoiKZm!UE>CIRZBprY-m0;TciSqFGl`2o@ACOC z5xuBJ=Jw9O4T-bo${pHvDSrOpustPg(X!DO&%IQPf5_}%8vR>n+b!1>-N9KH*W3T;2JN-buLMLo>cagZJW>TUG;61rcQP# z-(~&3Z*vZcE64v2E?u8|dQZ*H*}C7P^6s7}(&XK}pa16POXYKK8Ab2sh*mim*S77< zHT}b4k>>-KZ98`Dck7L&)9cRdT+k)4`{tp))!&N5cK>{PG~O9hY@sI01fa<6>r?8b XOt-IHrS9<-R7`rh`njxgN@xNAr!j{@ literal 0 HcmV?d00001 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels-to-6.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels-to-6.properties new file mode 100644 index 00000000..b463fb9e --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-5-channels-to-6.properties @@ -0,0 +1,12 @@ +PROPERTIES + +preferredNumberOfChannels=5 +content=3494 + +LOG + +Channels Used: 6 + +CODEWORDS + +111100111111213411232110000 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels-to-7.png b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels-to-7.png new file mode 100644 index 0000000000000000000000000000000000000000..5d528424ec0f003107efa53469c95069a6b873f5 GIT binary patch literal 1533 zcmeAS@N?(olHy`uVBq!ia0y~yV2lIeFC0JthJfQzehdt(M?75|Ln>~)z2jK+Sb>Kj z;9Y%Yn&JCW!^cZJoNi?9pH}K|^!P@@gkwLteu~!CN846?-FfwWb$pWEv8;2ezaHoo z*N@v%@$u2oQO0N>&>|(&3%wWVZ3Lz=RJw(CI19QrEO5(sFJ@zanhc}+nkgFGd6lCY!u1=;^P1Dn$(7g+jnhR ze#F}BW8W+OC96F&HvZj{%>BOpzIg6|BmP=do1;8*N?-1^5L$gEVtv*o=Rq5&xzO5$&?@2zN`@EvKnbW!={MSqG5aX(~ zdVfB@2|oYFyUjBZcmGJb-k=j8%YwB_<7~Vf+e!c6R;=PYI z_w4LDR(bDd;vVI5*5^Kdo42QS&wm*nAKNqW$7WmoNs`I`d1=F;*=K&==zVMZ{#C&XQ*x^8pIZDwvy)iRFl zHowf#xcj0bP(Ie?dcE=c6Q9<_dr4KS|0h$$W_i~7ar*n(J^9ZMFv(tZ|C|@G^z-FP z_s;Lj<{ke1Rj+aRn&dq@{odRDy?2BqZ^sF_dtX*PD101z`}xOn6*-a5C#*bL{yK%3 z*?|AqT_eHyD~{gCxOyhKIys^AZ4Gz+TgG2H@8_uApS-7&@xz%JKl$zzTIbhX`6cka z@8Or&J&Vs+ADVvefYVc#iMo>=pO$a^U^Z`0h5PH1-P^xDIr_Wg-UqLp!Fy(h9h(;C zw6C!|yH+aPgKv*|h53uHitlST-aixV{pJQ(ac=#`Ro&aC+&Fgei0_`O+dto`5bj*7 zFPAC%zV@%{Pg~hUt$d?k0IU_rO}+=!&ybF0~x zM?TlhpMLS^Y~M9Ib|t>AWUT$+(NXOW c_oV6>eBQr%!2KpR1yrtky85}Sb4q9e02jzU(*OVf literal 0 HcmV?d00001 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels-to-7.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels-to-7.properties new file mode 100644 index 00000000..f30dc180 --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-6-channels-to-7.properties @@ -0,0 +1,12 @@ +PROPERTIES + +preferredNumberOfChannels=6 +content=44073 + +LOG + +Channels Used: 7 + +CODEWORDS + +111100111111213223142111200 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels-to-8.png b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels-to-8.png new file mode 100644 index 0000000000000000000000000000000000000000..e2138acbd88cb79cf972732b27f3703c9a9b6799 GIT binary patch literal 1729 zcmeAS@N?(olHy`uVBq!ia0y~yU~B{8FC0Jt1{ubypBWg~Iy_w*Ln>~)y?cAo5(OTH zfPep&-`u`-?b^V}0;0?PwompnegfIJIvai?=neo!AyTZ()$>{R1ER4#o03PUc}g{EWw6LqsA;HX*X@(BlI3!+%nF9tZO@ zTCMz0D13N37jv8Jz6ILxz0pQ%c;nI~gp>_Cr<|22+M0Xai{)YU1nFhoOPpy%NVB<+Wa`UU@M7&%&}lz5Cb?pD{c$UDE5Y?&me1KX~&z{>;-}`;wpUx6J{A z+wU_S^}e4ve`v$`Q;#nkFfdPivD$k75raBj=U-dOQ)WoSrAX|bpO{oJ`QgQtN4|&s zUikdgo9z;9+YSZHIuQ5n|BH7w=g23`_-)X$lzmzA!tcI^&m;+J-!FT9cd2cxm$^vW za>+D#=hO$Pb2jli|C&4RsQTW-hIJpja_S1yFFZAopV{pbUn=wmd&M#^NY8(#qBk| zb>@`)!YPGYC!F7rclc;}pP62EXq5QM8$UE;)Mp3nnDfi#)iKw5Rw7dWE@wu2{VRI4 z`KI)Ao0yql@$W7DWYp$fVlxkyO!MFPUZOX`Vsn<4|6cK()BZetCVy$#vahdZUJaTw zJ-BxFv%aGXr{80m8`}9h=+&i<#j}!dWjgTe~DWM4f D8%2pX literal 0 HcmV?d00001 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels-to-8.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels-to-8.properties new file mode 100644 index 00000000..f76dc631 --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/basic-7-channels-to-8.properties @@ -0,0 +1,12 @@ +PROPERTIES + +preferredNumberOfChannels=7 +content=576689 + +LOG + +Channels Used: 8 + +CODEWORDS + +111100111111213211212213143 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/invalid-chars.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/invalid-chars.properties new file mode 100644 index 00000000..7d877c17 --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/invalid-chars.properties @@ -0,0 +1,7 @@ +PROPERTIES + +content=1.2 + +ERROR + +Invalid characters in data diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-few-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-few-channels.properties new file mode 100644 index 00000000..8eba40f1 --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-few-channels.properties @@ -0,0 +1,8 @@ +PROPERTIES + +preferredNumberOfChannels=2 +content=7742862 + +ERROR + +Invalid number of channels: 2 diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-long.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-long.properties new file mode 100644 index 00000000..8e73db78 --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-long.properties @@ -0,0 +1,7 @@ +PROPERTIES + +content=12345678 + +ERROR + +Input data too long diff --git a/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-many-channels.properties b/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-many-channels.properties new file mode 100644 index 00000000..6e6fa0df --- /dev/null +++ b/src/test/resources/uk/org/okapibarcode/backend/channelcode/too-many-channels.properties @@ -0,0 +1,8 @@ +PROPERTIES + +preferredNumberOfChannels=9 +content=7742862 + +ERROR + +Invalid number of channels: 9