test_iso4217.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /*
  2. libzint - the open source barcode library
  3. Copyright (C) 2021-2024 Robin Stuart <rstuart114@gmail.com>
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. 3. Neither the name of the project nor the names of its contributors
  13. may be used to endorse or promote products derived from this software
  14. without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  19. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. SUCH DAMAGE.
  26. */
  27. /* SPDX-License-Identifier: BSD-3-Clause */
  28. #include "testcommon.h"
  29. #include "../iso4217.h"
  30. static void test_numeric(const testCtx *const p_ctx) {
  31. struct item {
  32. int data;
  33. int ret;
  34. };
  35. /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
  36. struct item data[] = {
  37. /* 0*/ { -1, 0 },
  38. /* 1*/ { 0, 0 },
  39. /* 2*/ { 1, 0 },
  40. /* 3*/ { 2, 0 },
  41. /* 4*/ { 3, 0 },
  42. /* 5*/ { 4, 0 },
  43. /* 6*/ { 5, 0 },
  44. /* 7*/ { 6, 0 },
  45. /* 8*/ { 7, 0 },
  46. /* 9*/ { 8, 1 },
  47. /* 10*/ { 9, 0 },
  48. /* 11*/ { 10, 0 },
  49. /* 12*/ { 11, 0 },
  50. /* 13*/ { 12, 1 },
  51. /* 14*/ { 13, 0 },
  52. /* 15*/ { 14, 0 },
  53. /* 16*/ { 15, 0 },
  54. /* 17*/ { 16, 0 },
  55. /* 18*/ { 17, 0 },
  56. /* 19*/ { 18, 0 },
  57. /* 20*/ { 19, 0 },
  58. /* 21*/ { 20, 0 },
  59. /* 22*/ { 21, 0 },
  60. /* 23*/ { 31, 0 },
  61. /* 24*/ { 32, 1 },
  62. /* 25*/ { 33, 0 },
  63. /* 26*/ { 34, 0 },
  64. /* 27*/ { 35, 0 },
  65. /* 28*/ { 36, 1 },
  66. /* 29*/ { 37, 0 },
  67. /* 30*/ { 43, 0 },
  68. /* 31*/ { 44, 1 },
  69. /* 32*/ { 45, 0 },
  70. /* 33*/ { 49, 0 },
  71. /* 34*/ { 50, 1 },
  72. /* 35*/ { 51, 1 },
  73. /* 36*/ { 52, 1 },
  74. /* 37*/ { 53, 0 },
  75. /* 38*/ { 59, 0 },
  76. /* 39*/ { 60, 1 },
  77. /* 40*/ { 61, 0 },
  78. /* 41*/ { 62, 0 },
  79. /* 42*/ { 63, 0 },
  80. /* 43*/ { 64, 1 },
  81. /* 44*/ { 65, 0 },
  82. /* 45*/ { 66, 0 },
  83. /* 46*/ { 67, 0 },
  84. /* 47*/ { 68, 1 },
  85. /* 48*/ { 69, 0 },
  86. /* 49*/ { 70, 0 },
  87. /* 50*/ { 71, 0 },
  88. /* 51*/ { 72, 1 },
  89. /* 52*/ { 73, 0 },
  90. /* 53*/ { 80, 0 },
  91. /* 54*/ { 81, 0 },
  92. /* 55*/ { 82, 0 },
  93. /* 56*/ { 83, 0 },
  94. /* 57*/ { 84, 1 },
  95. /* 58*/ { 85, 0 },
  96. /* 59*/ { 89, 0 },
  97. /* 60*/ { 90, 1 },
  98. /* 61*/ { 91, 0 },
  99. /* 62*/ { 99, 0 },
  100. /* 63*/ { 100, 0 },
  101. /* 64*/ { 101, 0 },
  102. /* 65*/ { 102, 0 },
  103. /* 66*/ { 103, 0 },
  104. /* 67*/ { 104, 1 },
  105. /* 68*/ { 105, 0 },
  106. /* 69*/ { 110, 0 },
  107. /* 70*/ { 120, 0 },
  108. /* 71*/ { 130, 0 },
  109. /* 72*/ { 131, 0 },
  110. /* 73*/ { 132, 1 },
  111. /* 74*/ { 133, 0 },
  112. /* 75*/ { 143, 0 },
  113. /* 76*/ { 144, 1 },
  114. /* 77*/ { 145, 0 },
  115. /* 78*/ { 146, 0 },
  116. /* 79*/ { 147, 0 },
  117. /* 80*/ { 148, 0 },
  118. /* 81*/ { 149, 0 },
  119. /* 82*/ { 150, 0 },
  120. /* 83*/ { 160, 0 },
  121. /* 84*/ { 169, 0 },
  122. /* 85*/ { 170, 1 },
  123. /* 86*/ { 171, 0 },
  124. /* 87*/ { 180, 0 },
  125. /* 88*/ { 190, 0 },
  126. /* 89*/ { 191, 1 },
  127. /* 90*/ { 192, 1 },
  128. /* 91*/ { 193, 0 },
  129. /* 92*/ { 200, 0 },
  130. /* 93*/ { 210, 0 },
  131. /* 94*/ { 220, 0 },
  132. /* 95*/ { 221, 0 },
  133. /* 96*/ { 222, 1 },
  134. /* 97*/ { 223, 0 },
  135. /* 98*/ { 229, 0 },
  136. /* 99*/ { 230, 1 },
  137. /*100*/ { 231, 0 },
  138. /*101*/ { 232, 1 },
  139. /*102*/ { 233, 0 },
  140. /*103*/ { 234, 0 },
  141. /*104*/ { 235, 0 },
  142. /*105*/ { 236, 0 },
  143. /*106*/ { 237, 0 },
  144. /*107*/ { 238, 1 },
  145. /*108*/ { 239, 0 },
  146. /*109*/ { 240, 0 },
  147. /*110*/ { 241, 0 },
  148. /*111*/ { 242, 1 },
  149. /*112*/ { 243, 0 },
  150. /*113*/ { 250, 0 },
  151. /*114*/ { 260, 0 },
  152. /*115*/ { 269, 0 },
  153. /*116*/ { 270, 1 },
  154. /*117*/ { 271, 0 },
  155. /*118*/ { 280, 0 },
  156. /*119*/ { 290, 0 },
  157. /*120*/ { 291, 0 },
  158. /*121*/ { 292, 1 },
  159. /*122*/ { 293, 0 },
  160. /*123*/ { 300, 0 },
  161. /*124*/ { 310, 0 },
  162. /*125*/ { 319, 0 },
  163. /*126*/ { 320, 1 },
  164. /*127*/ { 321, 0 },
  165. /*128*/ { 322, 0 },
  166. /*129*/ { 323, 0 },
  167. /*130*/ { 324, 1 },
  168. /*131*/ { 325, 0 },
  169. /*132*/ { 330, 0 },
  170. /*133*/ { 331, 0 },
  171. /*134*/ { 332, 1 },
  172. /*135*/ { 333, 0 },
  173. /*136*/ { 339, 0 },
  174. /*137*/ { 340, 1 },
  175. /*138*/ { 341, 0 },
  176. /*139*/ { 350, 0 },
  177. /*140*/ { 351, 0 },
  178. /*141*/ { 352, 1 },
  179. /*142*/ { 353, 0 },
  180. /*143*/ { 359, 0 },
  181. /*144*/ { 360, 1 },
  182. /*145*/ { 361, 0 },
  183. /*146*/ { 367, 0 },
  184. /*147*/ { 368, 1 },
  185. /*148*/ { 369, 0 },
  186. /*149*/ { 370, 0 },
  187. /*150*/ { 380, 0 },
  188. /*151*/ { 390, 0 },
  189. /*152*/ { 391, 0 },
  190. /*153*/ { 392, 1 },
  191. /*154*/ { 393, 0 },
  192. /*155*/ { 397, 0 },
  193. /*156*/ { 398, 1 },
  194. /*157*/ { 399, 0 },
  195. /*158*/ { 400, 1 },
  196. /*159*/ { 401, 0 },
  197. /*160*/ { 409, 0 },
  198. /*161*/ { 410, 1 },
  199. /*162*/ { 411, 0 },
  200. /*163*/ { 425, 0 },
  201. /*164*/ { 426, 1 },
  202. /*165*/ { 427, 0 },
  203. /*166*/ { 428, 0 },
  204. /*167*/ { 429, 0 },
  205. /*168*/ { 430, 1 },
  206. /*169*/ { 431, 0 },
  207. /*170*/ { 432, 0 },
  208. /*171*/ { 433, 0 },
  209. /*172*/ { 434, 1 },
  210. /*173*/ { 435, 0 },
  211. /*174*/ { 436, 0 },
  212. /*175*/ { 437, 0 },
  213. /*176*/ { 438, 0 },
  214. /*177*/ { 439, 0 },
  215. /*178*/ { 440, 0 },
  216. /*179*/ { 441, 0 },
  217. /*180*/ { 442, 0 },
  218. /*181*/ { 443, 0 },
  219. /*182*/ { 450, 0 },
  220. /*183*/ { 460, 0 },
  221. /*184*/ { 470, 0 },
  222. /*185*/ { 479, 0 },
  223. /*186*/ { 480, 1 },
  224. /*187*/ { 481, 0 },
  225. /*188*/ { 495, 0 },
  226. /*189*/ { 496, 1 },
  227. /*190*/ { 497, 0 },
  228. /*191*/ { 498, 1 },
  229. /*192*/ { 499, 0 },
  230. /*193*/ { 500, 0 },
  231. /*194*/ { 501, 0 },
  232. /*195*/ { 502, 0 },
  233. /*196*/ { 503, 0 },
  234. /*197*/ { 504, 1 },
  235. /*198*/ { 505, 0 },
  236. /*199*/ { 510, 0 },
  237. /*200*/ { 520, 0 },
  238. /*201*/ { 530, 0 },
  239. /*202*/ { 540, 0 },
  240. /*203*/ { 550, 0 },
  241. /*204*/ { 557, 0 },
  242. /*205*/ { 558, 1 },
  243. /*206*/ { 559, 0 },
  244. /*207*/ { 560, 0 },
  245. /*208*/ { 561, 0 },
  246. /*209*/ { 562, 0 },
  247. /*210*/ { 563, 0 },
  248. /*211*/ { 564, 0 },
  249. /*212*/ { 565, 0 },
  250. /*213*/ { 566, 1 },
  251. /*214*/ { 567, 0 },
  252. /*215*/ { 570, 0 },
  253. /*216*/ { 580, 0 },
  254. /*217*/ { 589, 0 },
  255. /*218*/ { 590, 1 },
  256. /*219*/ { 591, 0 },
  257. /*220*/ { 597, 0 },
  258. /*221*/ { 598, 1 },
  259. /*222*/ { 599, 0 },
  260. /*223*/ { 600, 1 },
  261. /*224*/ { 601, 0 },
  262. /*225*/ { 610, 0 },
  263. /*226*/ { 611, 0 },
  264. /*227*/ { 612, 0 },
  265. /*228*/ { 613, 0 },
  266. /*229*/ { 620, 0 },
  267. /*230*/ { 630, 0 },
  268. /*231*/ { 640, 0 },
  269. /*232*/ { 650, 0 },
  270. /*233*/ { 660, 0 },
  271. /*234*/ { 670, 0 },
  272. /*235*/ { 677, 0 },
  273. /*236*/ { 678, 0 },
  274. /*237*/ { 679, 0 },
  275. /*238*/ { 680, 0 },
  276. /*239*/ { 681, 0 },
  277. /*240*/ { 682, 1 },
  278. /*241*/ { 683, 0 },
  279. /*242*/ { 689, 0 },
  280. /*243*/ { 690, 1 },
  281. /*244*/ { 691, 0 },
  282. /*245*/ { 700, 0 },
  283. /*246*/ { 701, 0 },
  284. /*247*/ { 702, 1 },
  285. /*248*/ { 703, 0 },
  286. /*249*/ { 704, 1 },
  287. /*250*/ { 705, 0 },
  288. /*251*/ { 706, 1 },
  289. /*252*/ { 707, 0 },
  290. /*253*/ { 708, 0 },
  291. /*254*/ { 709, 0 },
  292. /*255*/ { 710, 1 },
  293. /*256*/ { 711, 0 },
  294. /*257*/ { 720, 0 },
  295. /*258*/ { 730, 0 },
  296. /*259*/ { 740, 0 },
  297. /*260*/ { 750, 0 },
  298. /*261*/ { 751, 0 },
  299. /*262*/ { 752, 1 },
  300. /*263*/ { 753, 0 },
  301. /*264*/ { 759, 0 },
  302. /*265*/ { 760, 1 },
  303. /*266*/ { 761, 0 },
  304. /*267*/ { 770, 0 },
  305. /*268*/ { 779, 0 },
  306. /*269*/ { 780, 1 },
  307. /*270*/ { 781, 0 },
  308. /*271*/ { 790, 0 },
  309. /*272*/ { 799, 0 },
  310. /*273*/ { 800, 1 },
  311. /*274*/ { 801, 0 },
  312. /*275*/ { 810, 0 },
  313. /*276*/ { 820, 0 },
  314. /*277*/ { 830, 0 },
  315. /*278*/ { 839, 0 },
  316. /*279*/ { 840, 1 },
  317. /*280*/ { 841, 0 },
  318. /*281*/ { 857, 0 },
  319. /*282*/ { 858, 1 },
  320. /*283*/ { 859, 0 },
  321. /*284*/ { 860, 1 },
  322. /*285*/ { 861, 0 },
  323. /*286*/ { 870, 0 },
  324. /*287*/ { 880, 0 },
  325. /*288*/ { 881, 0 },
  326. /*289*/ { 882, 1 },
  327. /*290*/ { 883, 0 },
  328. /*291*/ { 884, 0 },
  329. /*292*/ { 885, 0 },
  330. /*293*/ { 886, 1 },
  331. /*294*/ { 887, 0 },
  332. /*295*/ { 888, 0 },
  333. /*296*/ { 889, 0 },
  334. /*297*/ { 890, 0 },
  335. /*298*/ { 891, 0 },
  336. /*299*/ { 892, 0 },
  337. /*300*/ { 893, 0 },
  338. /*301*/ { 894, 0 },
  339. /*302*/ { 895, 0 },
  340. /*303*/ { 896, 0 },
  341. /*304*/ { 897, 0 },
  342. /*305*/ { 898, 0 },
  343. /*306*/ { 899, 0 },
  344. /*307*/ { 900, 0 },
  345. /*308*/ { 901, 1 },
  346. /*309*/ { 902, 0 },
  347. /*310*/ { 924, 1 },
  348. /*311*/ { 925, 1 },
  349. /*312*/ { 926, 0 },
  350. /*313*/ { 927, 1 },
  351. /*314*/ { 928, 1 },
  352. /*315*/ { 929, 1 },
  353. /*316*/ { 930, 1 },
  354. /*317*/ { 931, 1 },
  355. /*318*/ { 932, 1 }, /* TODO: 1 -> 0, 1 Sept 2024 */
  356. /*319*/ { 933, 1 },
  357. /*320*/ { 934, 1 },
  358. /*321*/ { 935, 0 },
  359. /*322*/ { 936, 1 },
  360. /*323*/ { 937, 0 },
  361. /*324*/ { 938, 1 },
  362. /*325*/ { 939, 0 },
  363. /*326*/ { 940, 1 },
  364. /*327*/ { 941, 1 },
  365. /*328*/ { 942, 0 },
  366. /*329*/ { 943, 1 },
  367. /*330*/ { 944, 1 },
  368. /*331*/ { 945, 0 },
  369. /*332*/ { 946, 1 },
  370. /*333*/ { 947, 1 },
  371. /*334*/ { 948, 1 },
  372. /*335*/ { 949, 1 },
  373. /*336*/ { 950, 1 },
  374. /*337*/ { 951, 1 },
  375. /*338*/ { 952, 1 },
  376. /*339*/ { 953, 1 },
  377. /*340*/ { 954, 0 },
  378. /*341*/ { 955, 1 },
  379. /*342*/ { 956, 1 },
  380. /*343*/ { 957, 1 },
  381. /*344*/ { 958, 1 },
  382. /*345*/ { 959, 1 },
  383. /*346*/ { 960, 1 },
  384. /*347*/ { 961, 1 },
  385. /*348*/ { 962, 1 },
  386. /*349*/ { 963, 1 },
  387. /*350*/ { 964, 1 },
  388. /*351*/ { 965, 1 },
  389. /*352*/ { 966, 0 },
  390. /*353*/ { 967, 1 },
  391. /*354*/ { 968, 1 },
  392. /*355*/ { 969, 1 },
  393. /*356*/ { 970, 1 },
  394. /*357*/ { 971, 1 },
  395. /*358*/ { 972, 1 },
  396. /*359*/ { 973, 1 },
  397. /*360*/ { 974, 0 },
  398. /*361*/ { 975, 1 },
  399. /*362*/ { 976, 1 },
  400. /*363*/ { 977, 1 },
  401. /*364*/ { 978, 1 },
  402. /*365*/ { 979, 1 },
  403. /*366*/ { 980, 1 },
  404. /*367*/ { 981, 1 },
  405. /*368*/ { 982, 0 },
  406. /*369*/ { 983, 0 },
  407. /*370*/ { 984, 1 },
  408. /*371*/ { 985, 1 },
  409. /*372*/ { 986, 1 },
  410. /*373*/ { 987, 0 },
  411. /*374*/ { 988, 0 },
  412. /*375*/ { 989, 0 },
  413. /*376*/ { 990, 1 },
  414. /*377*/ { 991, 0 },
  415. /*378*/ { 992, 0 },
  416. /*379*/ { 993, 0 },
  417. /*380*/ { 994, 1 },
  418. /*381*/ { 995, 0 },
  419. /*382*/ { 996, 0 },
  420. /*383*/ { 997, 1 },
  421. /*384*/ { 998, 0 },
  422. /*385*/ { 999, 1 },
  423. /*386*/ { 1000, 0 },
  424. /*387*/ { 2000, 0 },
  425. };
  426. int data_size = ARRAY_SIZE(data);
  427. int i, ret;
  428. testStart("test_numeric");
  429. for (i = 0; i < data_size; i++) {
  430. if (testContinue(p_ctx, i)) continue;
  431. ret = iso4217_numeric(data[i].data);
  432. assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret);
  433. }
  434. testFinish();
  435. }
  436. /* Binary chop version: Whether ISO 4217 numeric */
  437. static int bc_iso4217_numeric(int cc) {
  438. static const short codes[181] = {
  439. /*ALL*/ 8, /*DZD*/ 12, /*ARS*/ 32, /*AUD*/ 36, /*BSD*/ 44, /*BHD*/ 48, /*BDT*/ 50, /*AMD*/ 51, /*BBD*/ 52, /*BMD*/ 60,
  440. /*BTN*/ 64, /*BOB*/ 68, /*BWP*/ 72, /*BZD*/ 84, /*SBD*/ 90, /*BND*/ 96, /*MMK*/ 104, /*BIF*/ 108, /*KHR*/ 116, /*CAD*/ 124,
  441. /*CVE*/ 132, /*KYD*/ 136, /*LKR*/ 144, /*CLP*/ 152, /*CNY*/ 156, /*COP*/ 170, /*KMF*/ 174, /*CRC*/ 188, /*HRK*/ 191, /*CUP*/ 192,
  442. /*CZK*/ 203, /*DKK*/ 208, /*DOP*/ 214, /*SVC*/ 222, /*ETB*/ 230, /*ERN*/ 232, /*FKP*/ 238, /*FJD*/ 242, /*DJF*/ 262, /*GMD*/ 270,
  443. /*GIP*/ 292, /*GTQ*/ 320, /*GNF*/ 324, /*GYD*/ 328, /*HTG*/ 332, /*HNL*/ 340, /*HKD*/ 344, /*HUF*/ 348, /*ISK*/ 352, /*INR*/ 356,
  444. /*IDR*/ 360, /*IRR*/ 364, /*IQD*/ 368, /*ILS*/ 376, /*JMD*/ 388, /*JPY*/ 392, /*KZT*/ 398, /*JOD*/ 400, /*KES*/ 404, /*KPW*/ 408,
  445. /*KRW*/ 410, /*KWD*/ 414, /*KGS*/ 417, /*LAK*/ 418, /*LBP*/ 422, /*LSL*/ 426, /*LRD*/ 430, /*LYD*/ 434, /*MOP*/ 446, /*MWK*/ 454,
  446. /*MYR*/ 458, /*MVR*/ 462, /*MUR*/ 480, /*MXN*/ 484, /*MNT*/ 496, /*MDL*/ 498, /*MAD*/ 504, /*OMR*/ 512, /*NAD*/ 516, /*NPR*/ 524,
  447. /*ANG*/ 532, /*AWG*/ 533, /*VUV*/ 548, /*NZD*/ 554, /*NIO*/ 558, /*NGN*/ 566, /*NOK*/ 578, /*PKR*/ 586, /*PAB*/ 590, /*PGK*/ 598,
  448. /*PYG*/ 600, /*PEN*/ 604, /*PHP*/ 608, /*QAR*/ 634, /*RUB*/ 643, /*RWF*/ 646, /*SHP*/ 654, /*SAR*/ 682, /*SCR*/ 690, /*SLL*/ 694,
  449. /*SGD*/ 702, /*VND*/ 704, /*SOS*/ 706, /*ZAR*/ 710, /*SSP*/ 728, /*SZL*/ 748, /*SEK*/ 752, /*CHF*/ 756, /*SYP*/ 760, /*THB*/ 764,
  450. /*TOP*/ 776, /*TTD*/ 780, /*AED*/ 784, /*TND*/ 788, /*UGX*/ 800, /*MKD*/ 807, /*EGP*/ 818, /*GBP*/ 826, /*TZS*/ 834, /*USD*/ 840,
  451. /*UYU*/ 858, /*UZS*/ 860, /*WST*/ 882, /*YER*/ 886, /*TWD*/ 901, /*ZWG*/ 924, /*SLE*/ 925, /*UYW*/ 927, /*VES*/ 928, /*MRU*/ 929,
  452. /*STN*/ 930, /*CUC*/ 931, /*ZWL*/ 932, /* TODO: remove 1 Sept 2024 */
  453. /*BYN*/ 933, /*TMT*/ 934, /*GHS*/ 936, /*SDG*/ 938, /*UYI*/ 940, /*RSD*/ 941, /*MZN*/ 943, /*AZN*/ 944,
  454. /*RON*/ 946, /*CHE*/ 947, /*CHW*/ 948, /*TRY*/ 949, /*XAF*/ 950, /*XCD*/ 951, /*XOF*/ 952, /*XPF*/ 953, /*XBA*/ 955, /*XBB*/ 956,
  455. /*XBC*/ 957, /*XBD*/ 958, /*XAU*/ 959, /*XDR*/ 960, /*XAG*/ 961, /*XPT*/ 962, /*XTS*/ 963, /*XPD*/ 964, /*XUA*/ 965, /*ZMW*/ 967,
  456. /*SRD*/ 968, /*MGA*/ 969, /*COU*/ 970, /*AFN*/ 971, /*TJS*/ 972, /*AOA*/ 973, /*BGN*/ 975, /*CDF*/ 976, /*BAM*/ 977, /*EUR*/ 978,
  457. /*MXV*/ 979, /*UAH*/ 980, /*GEL*/ 981, /*BOV*/ 984, /*PLN*/ 985, /*BRL*/ 986, /*CLF*/ 990, /*XSU*/ 994, /*USN*/ 997, /*XXX*/ 999,
  458. };
  459. int s = 0, e = ARRAY_SIZE(codes) - 1;
  460. while (s <= e) {
  461. int m = (s + e) / 2;
  462. if (codes[m] < cc) {
  463. s = m + 1;
  464. } else if (codes[m] > cc) {
  465. e = m - 1;
  466. } else {
  467. return 1;
  468. }
  469. }
  470. return 0;
  471. }
  472. static void test_numeric_bc(const testCtx *const p_ctx) {
  473. int i, ret, bc_ret;
  474. testStart("test_numeric_bc");
  475. for (i = 0; i < 1001; i++) {
  476. if (testContinue(p_ctx, i)) continue;
  477. ret = iso4217_numeric(i);
  478. bc_ret = bc_iso4217_numeric(i);
  479. assert_equal(ret, bc_ret, "i:%d ret %d != bc_ret %d\n", i, ret, bc_ret);
  480. }
  481. testFinish();
  482. }
  483. int main(int argc, char *argv[]) {
  484. testFunction funcs[] = { /* name, func */
  485. { "test_numeric", test_numeric },
  486. { "test_numeric_bc", test_numeric_bc },
  487. };
  488. testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
  489. testReport();
  490. return 0;
  491. }
  492. /* vim: set ts=4 sw=4 et : */