taddlong.pp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. { Program to test Code generator secondadd() }
  2. { with longint values }
  3. { FUNCTIONAL PRE-REQUISITES: }
  4. { - assignments function correctly. }
  5. { - if statements function correctly. }
  6. { - subroutine calls function correctly. }
  7. procedure fail;
  8. begin
  9. WriteLn('Failed!');
  10. halt(1);
  11. end;
  12. procedure LongintTestAdd;
  13. var
  14. i: longint;
  15. j: longint;
  16. result : boolean;
  17. begin
  18. Write('Longint + Longint test...');
  19. result := true;
  20. i:=0;
  21. j:=0;
  22. i := i + -10000;
  23. if i <> -10000 then
  24. result := false;
  25. j := 32767;
  26. i := i + j;
  27. if i <> 22767 then
  28. result := false;
  29. i := i + j + 50000;
  30. if i <> 105534 then
  31. result := false;
  32. i:=0;
  33. j:=10000;
  34. i:= i + j + j + i + j;
  35. if i <> 30000 then
  36. result := false;
  37. if not result then
  38. Fail
  39. else
  40. WriteLn('Success.');
  41. end;
  42. procedure LongintTestSub;
  43. var
  44. i, j, k : longint;
  45. result : boolean;
  46. begin
  47. Write('Longint - Longint test...');
  48. result := true;
  49. i:=100000;
  50. j:=54;
  51. k:=56;
  52. i:= i - 100;
  53. if i <> 99900 then
  54. result := false;
  55. i := i - j - k - 100;
  56. if i <> 99690 then
  57. result := false;
  58. i:=100;
  59. j:=1000;
  60. k:=100;
  61. i:= j - i - k;
  62. if i <> 800 then
  63. result := false;
  64. if not result then
  65. Fail
  66. else
  67. WriteLn('Success.');
  68. end;
  69. procedure LongintTestMul;
  70. var
  71. i : longint;
  72. j : longint;
  73. k: longint;
  74. result: boolean;
  75. begin
  76. Write('Longint * Longint test...');
  77. result := true;
  78. i:=0;
  79. j:=0;
  80. i:=i * 32;
  81. if i <> 0 then
  82. result := false;
  83. i:=10;
  84. i:=i * -16;
  85. if i <> -160 then
  86. result := false;
  87. j:=10000;
  88. i:=-10000;
  89. i:=i * j;
  90. if i <> -100000000 then
  91. result := false;
  92. i:=1;
  93. j:=10;
  94. k:=16;
  95. i := i * j * k;
  96. if i <> 160 then
  97. result := false;
  98. i := 1;
  99. j := 10;
  100. k := 16;
  101. i := i * 10 * j * i * j * 16 * k;
  102. if i <> 256000 then
  103. result := false;
  104. if not result then
  105. Fail
  106. else
  107. WriteLn('Success.');
  108. end;
  109. procedure LongintTestXor;
  110. var
  111. i, j : Longint;
  112. result : boolean;
  113. begin
  114. Write('Longint XOR Longint test...');
  115. result := true;
  116. i := 0;
  117. j := 0;
  118. i := i xor $1000001;
  119. if i <> $1000001 then
  120. result := false;
  121. i:=0;
  122. j:=$10000001;
  123. i:=i xor j;
  124. if i <> $10000001 then
  125. result := false;
  126. i := 0;
  127. j := $55555555;
  128. i := i xor j xor $AAAAAAAA;
  129. if i <> longint($FFFFFFFF) then
  130. result := false;
  131. if not result then
  132. Fail
  133. else
  134. WriteLn('Success.');
  135. end;
  136. procedure LongintTestOr;
  137. var
  138. i,j : Longint;
  139. result : boolean;
  140. Begin
  141. Write('Longint OR Longint test...');
  142. result := true;
  143. i := 0;
  144. j := 0;
  145. i := i or $1000001;
  146. if i <> $1000001 then
  147. result := false;
  148. i:=0;
  149. j:=$10000001;
  150. i:=i or j;
  151. if i <> $10000001 then
  152. result := false;
  153. i := 0;
  154. j := $55555555;
  155. i := i or j or longint($AAAAAAAA);
  156. if i <> longint($FFFFFFFF) then
  157. result := false;
  158. if not result then
  159. Fail
  160. else
  161. WriteLn('Success.');
  162. end;
  163. procedure LongintTestAnd;
  164. var
  165. i,j : Longint;
  166. result : boolean;
  167. Begin
  168. Write('Longint AND Longint test...');
  169. result := true;
  170. i := $1000001;
  171. j := 0;
  172. i := i and $1000001;
  173. if i <> $1000001 then
  174. result := false;
  175. i:=0;
  176. j:=$10000001;
  177. i:=i and j;
  178. if i <> 0 then
  179. result := false;
  180. i := longint($FFFFFFFF);
  181. j := $55555555;
  182. i := i and j;
  183. if i <> $55555555 then
  184. result := false;
  185. i := longint($FFFFFFFF);
  186. i := i and longint($AAAAAAAA);
  187. if i <> longint($AAAAAAAA) then
  188. result := false;
  189. i := 0;
  190. j := $55555555;
  191. i := i and j and longint($AAAAAAAA);
  192. if i <> 0 then
  193. result := false;
  194. if not result then
  195. Fail
  196. else
  197. WriteLn('Success.');
  198. end;
  199. procedure LongintTestEqual;
  200. var
  201. i,j : Longint;
  202. result : boolean;
  203. Begin
  204. Write('Longint = Longint test...');
  205. result := true;
  206. i := $1000001;
  207. j := 0;
  208. if i = 0 then
  209. result := false;
  210. if i = j then
  211. result := false;
  212. if j = i then
  213. result := false;
  214. if not result then
  215. Fail
  216. else
  217. WriteLn('Success.');
  218. end;
  219. procedure LongintTestNotEqual;
  220. var
  221. i,j : Longint;
  222. result : boolean;
  223. Begin
  224. Write('Longint <> Longint test...');
  225. result := true;
  226. i := $1000001;
  227. j := $1000001;
  228. if i <> $1000001 then
  229. result := false;
  230. if i <> j then
  231. result := false;
  232. if j <> i then
  233. result := false;
  234. if not result then
  235. Fail
  236. else
  237. WriteLn('Success.');
  238. end;
  239. procedure LongintTestLE;
  240. var
  241. i, j: Longint;
  242. result : boolean;
  243. begin
  244. Write('Longint <= Longint test...');
  245. result := true;
  246. i := -1;
  247. j := -2;
  248. if i <= j then
  249. result := false;
  250. i := -2;
  251. j := $FFFF;
  252. if i >= j then
  253. result := false;
  254. i := longint($FFFFFFFF);
  255. if i <= longint($FFFFFFFE) then
  256. result := false;
  257. j := longint($FFFFFFFF);
  258. if i <= j then
  259. begin
  260. if result then
  261. WriteLn('Success.')
  262. else
  263. Fail;
  264. end
  265. else
  266. Fail;
  267. end;
  268. procedure LongintTestGE;
  269. var
  270. i, j: Longint;
  271. result : boolean;
  272. begin
  273. Write('Longint >= Longint test...');
  274. result := true;
  275. i := longint($FFFFFFFE);
  276. j := longint($FFFFFFFF);
  277. if i >= j then
  278. result := false;
  279. i := longint($FFFFFFFE);
  280. j := longint($FFFFFFFF);
  281. if i > j then
  282. result := false;
  283. i := longint($FFFFFFFE);
  284. if i > longint($FFFFFFFE) then
  285. result := false;
  286. i := longint($FFFFFFFF);
  287. j := longint($FFFFFFFF);
  288. if i >= j then
  289. begin
  290. if result then
  291. WriteLn('Success.')
  292. else
  293. Fail;
  294. end
  295. else
  296. Fail;
  297. end;
  298. Begin
  299. { These should be tested first, since if they do not }
  300. { work, they will false all other results. }
  301. LongintTestEqual;
  302. LongintTestNotEqual;
  303. LongintTestAdd;
  304. LongintTestMul;
  305. LongintTestOr;
  306. LongintTestAnd;
  307. LongintTestXor;
  308. LongintTestLe;
  309. LongintTestGe;
  310. LongintTestSub;
  311. end.