tparray7.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. {$mode macpas}
  2. {$r-}
  3. procedure error(l: longint);
  4. begin
  5. writeln('error near ',l);
  6. halt(1);
  7. end;
  8. procedure test8bit;
  9. type
  10. ta = 0..1;
  11. tb = packed array[0..999] of ta;
  12. tc = array[0..124] of byte;
  13. const
  14. results: array[0..9] of ta = (1,0,1,1,1,0,1,1,1,0);
  15. var
  16. a: ta;
  17. b: tb;
  18. i,j: longint;
  19. begin
  20. fillchar(b,sizeof(b),0);
  21. for i := low(results) to high(results) do
  22. begin
  23. b[i] := results[i];
  24. for j := succ(i) to high(results) do
  25. if b[j] <> 0 then
  26. error(201);
  27. if b[i] <> results[i] then
  28. error(202);
  29. end;
  30. if (b[0] <> results[0]) then
  31. error(1);
  32. if (b[1] <> results[1]) then
  33. error(2);
  34. if (b[2] <> results[2]) then
  35. error(3);
  36. if (b[3] <> results[3]) then
  37. error(4);
  38. if (b[4] <> results[4]) then
  39. error(5);
  40. for i := low(results) to high(results) do
  41. if b[i] <> results[i] then
  42. error(7);
  43. end;
  44. procedure test8to16bit;
  45. type
  46. ta = 0..7;
  47. tb = packed array[0..1000] of ta;
  48. const
  49. results: array[0..5] of ta = (2,4,1,7,5,1);
  50. var
  51. a: ta;
  52. b: tb;
  53. i,j: longint;
  54. begin
  55. fillchar(b,sizeof(b),$ff);
  56. for i := low(results) to high(results) do
  57. begin
  58. b[i] := results[i];
  59. for j := succ(i) to high(results) do
  60. if b[j] <> high(ta) then
  61. error(211);
  62. if b[i] <> results[i] then
  63. error(212);
  64. end;
  65. if (b[0] <> results[0]) then
  66. error(11);
  67. if (b[1] <> results[1]) then
  68. error(12);
  69. if (b[2] <> results[2]) then
  70. error(13);
  71. if (b[3] <> results[3]) then
  72. error(14);
  73. if (b[4] <> results[4]) then
  74. error(15);
  75. if (b[5] <> results[5]) then
  76. error(155);
  77. for i := low(results) to high(results) do
  78. if b[i] <> results[i] then
  79. error(17);
  80. end;
  81. procedure test16bit;
  82. type
  83. ta = 0..511;
  84. tb = packed array[0..799] of ta;
  85. tc = array[0..899] of byte;
  86. const
  87. results: array[0..4] of ta = (356,39,485,100,500);
  88. var
  89. a: ta;
  90. b: tb;
  91. i,j: longint;
  92. begin
  93. fillchar(b,sizeof(b),$ff);
  94. for i := low(results) to high(results) do
  95. begin
  96. b[i] := results[i];
  97. for j := succ(i) to high(results) do
  98. if b[j] <> high(ta) then
  99. error(221);
  100. if b[i] <> results[i] then
  101. error(222);
  102. end;
  103. if (b[0] <> results[0]) then
  104. error(21);
  105. if (b[1] <> results[1]) then
  106. error(22);
  107. if (b[2] <> results[2]) then
  108. error(23);
  109. if (b[3] <> results[3]) then
  110. error(24);
  111. if (b[4] <> results[4]) then
  112. error(25);
  113. for i := low(results) to high(results) do
  114. if b[i] <> results[i] then
  115. error(27);
  116. end;
  117. procedure test16to24bit;
  118. type
  119. ta = 0..2047;
  120. tb = packed array[0..799] of ta;
  121. tc = array[0..1099] of byte;
  122. const
  123. results: array[0..4] of ta = (1000,67,853,512,759);
  124. var
  125. a: ta;
  126. b: tb;
  127. i,j: longint;
  128. begin
  129. fillchar(b,sizeof(b),$ff);
  130. for i := low(results) to high(results) do
  131. begin
  132. b[i] := results[i];
  133. for j := succ(i) to high(results) do
  134. if b[j] <> high(ta) then
  135. error(231);
  136. if b[i] <> results[i] then
  137. error(232);
  138. end;
  139. if (b[0] <> results[0]) then
  140. error(31);
  141. if (b[1] <> results[1]) then
  142. error(32);
  143. if (b[2] <> results[2]) then
  144. error(33);
  145. if (b[3] <> results[3]) then
  146. error(34);
  147. if (b[4] <> results[4]) then
  148. error(35);
  149. for i := low(results) to high(results) do
  150. if b[i] <> results[i] then
  151. error(37);
  152. end;
  153. procedure test32bit;
  154. type
  155. ta = 0..(1 shl 19) - 1;
  156. tb = packed array[0..799] of ta;
  157. tc = array[0..1899] of byte;
  158. const
  159. results: array[0..4] of ta = ($0002F687,$00032222,$000178EE,$000057970,$0007E1D2);
  160. var
  161. a: ta;
  162. b: tb;
  163. i,j: longint;
  164. begin
  165. fillchar(b,sizeof(b),$ff);
  166. for i := low(results) to high(results) do
  167. begin
  168. b[i] := results[i];
  169. for j := succ(i) to high(results) do
  170. if b[j] <> high(ta) then
  171. error(241);
  172. if b[i] <> results[i] then
  173. error(242);
  174. end;
  175. if (b[0] <> results[0]) then
  176. error(41);
  177. if (b[1] <> results[1]) then
  178. error(42);
  179. if (b[2] <> results[2]) then
  180. error(43);
  181. if (b[3] <> results[3]) then
  182. error(44);
  183. if (b[4] <> results[4]) then
  184. error(45);
  185. for i := low(results) to high(results) do
  186. if b[i] <> results[i] then
  187. error(47);
  188. end;
  189. procedure test32to40bit;
  190. type
  191. ta = 0..$7fffffff;
  192. tb = packed array[0..799] of ta;
  193. tc = array[0..3099] of byte;
  194. const
  195. results: array[0..4] of ta = ($71567851,$56789ABD,$50F11178,$39D68DDC,$6C7A5A7);
  196. var
  197. a: ta;
  198. b: tb;
  199. i,j: longint;
  200. begin
  201. fillchar(b,sizeof(b),$ff);
  202. for i := low(results) to high(results) do
  203. begin
  204. b[i] := results[i];
  205. for j := succ(i) to high(results) do
  206. if b[j] <> high(ta) then
  207. error(251);
  208. if b[i] <> results[i] then
  209. error(252);
  210. end;
  211. if (b[0] <> results[0]) then
  212. error(51);
  213. if (b[1] <> results[1]) then
  214. error(52);
  215. if (b[2] <> results[2]) then
  216. error(53);
  217. if (b[3] <> results[3]) then
  218. error(54);
  219. if (b[4] <> results[4]) then
  220. error(55);
  221. for i := low(results) to high(results) do
  222. if b[i] <> results[i] then
  223. error(57);
  224. end;
  225. begin
  226. test8bit;
  227. test8to16bit;
  228. test16bit;
  229. test16to24bit;
  230. test32bit;
  231. test32to40bit;
  232. end.