taddbool.pp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. { Program to test Code generator secondadd() }
  2. { with boolean values. }
  3. { FUNCTIONAL PRE-REQUISITES: }
  4. { - assignments function correctly. }
  5. { - if statements function correctly. }
  6. { - subroutine calls function correctly. }
  7. Program TAddBool;
  8. {$IFDEF VER70}
  9. TYPE
  10. cardinal = longint;
  11. {$ENDIF}
  12. procedure fail;
  13. begin
  14. WriteLn('Failed!');
  15. halt(1);
  16. end;
  17. { ---------------------------- BOOLEAN TEST ----------------------------- }
  18. { secondadd() }
  19. { ----------------------------------------------------------------------- }
  20. procedure BoolTestAnd;
  21. var
  22. bb1, bb2: boolean;
  23. wb1, wb2: wordbool;
  24. lb1, lb2: longbool;
  25. result : boolean;
  26. begin
  27. result := true;
  28. { BOOLEAN AND BOOLEAN }
  29. Write('boolean AND boolean test...');
  30. bb1 := true;
  31. bb2 := false;
  32. if bb1 and bb2 then
  33. result := false;
  34. if bb2 then
  35. result := false;
  36. bb1 := false;
  37. bb2 := false;
  38. if bb1 and bb2 then
  39. result := false;
  40. bb1 := bb1 and bb2;
  41. if bb1 then
  42. result := false;
  43. if bb1 and FALSE then
  44. result := false;
  45. bb1 := true;
  46. bb2 := true;
  47. if bb1 and bb2 then
  48. begin
  49. if result then
  50. WriteLn('Success.')
  51. else
  52. Fail;
  53. end
  54. else
  55. Fail;
  56. { WORDBOOL AND WORDBOOL }
  57. result := true;
  58. Write('wordbool AND wordbool test...');
  59. wb1 := true;
  60. wb2 := false;
  61. if wb1 and wb2 then
  62. result := false;
  63. if wb2 then
  64. result := false;
  65. wb1 := false;
  66. wb2 := false;
  67. if wb1 and wb2 then
  68. result := false;
  69. wb1 := wb1 and wb2;
  70. if wb1 then
  71. result := false;
  72. if wb1 and FALSE then
  73. result := false;
  74. wb1 := true;
  75. wb2 := true;
  76. if wb1 and wb2 then
  77. begin
  78. if result then
  79. WriteLn('Success.')
  80. else
  81. Fail;
  82. end
  83. else
  84. Fail;
  85. { LONGBOOL AND LONGBOOL }
  86. result := true;
  87. Write('longbool AND longbool test...');
  88. lb1 := true;
  89. lb2 := false;
  90. if lb1 and lb2 then
  91. result := false;
  92. if lb2 then
  93. result := false;
  94. lb1 := false;
  95. lb2 := false;
  96. if lb1 and lb2 then
  97. result := false;
  98. lb1 := lb1 and lb2;
  99. if lb1 then
  100. result := false;
  101. if lb1 and FALSE then
  102. result := false;
  103. lb1 := true;
  104. lb2 := true;
  105. if lb1 and lb2 then
  106. begin
  107. if result then
  108. WriteLn('Success.')
  109. else
  110. Fail;
  111. end
  112. else
  113. Fail;
  114. end;
  115. procedure BoolTestOr;
  116. var
  117. bb1, bb2: boolean;
  118. wb1, wb2: wordbool;
  119. lb1, lb2: longbool;
  120. result : boolean;
  121. begin
  122. result := false;
  123. { BOOLEAN AND BOOLEAN }
  124. Write('boolean OR boolean test...');
  125. bb1 := true;
  126. bb2 := false;
  127. if bb1 or bb2 then
  128. result := true;
  129. bb1 := false;
  130. bb2 := false;
  131. if bb1 or bb2 then
  132. result := false;
  133. bb1 := bb1 or bb2;
  134. if bb1 then
  135. result := false;
  136. if bb1 or FALSE then
  137. result := false;
  138. bb1 := true;
  139. bb2 := true;
  140. if bb1 or bb2 then
  141. begin
  142. if result then
  143. WriteLn('Success.')
  144. else
  145. Fail;
  146. end
  147. else
  148. Fail;
  149. { WORDBOOL AND WORDBOOL }
  150. result := false;
  151. Write('wordbool OR wordbool test...');
  152. wb1 := true;
  153. wb2 := false;
  154. if wb1 or wb2 then
  155. result := true;
  156. wb1 := false;
  157. wb2 := false;
  158. if wb1 or wb2 then
  159. result := false;
  160. wb1 := wb1 or wb2;
  161. if wb1 then
  162. result := false;
  163. if wb1 or FALSE then
  164. result := false;
  165. wb1 := true;
  166. wb2 := true;
  167. if wb1 or wb2 then
  168. begin
  169. if result then
  170. WriteLn('Success.')
  171. else
  172. Fail;
  173. end
  174. else
  175. Fail;
  176. { LONGBOOL AND LONGBOOL }
  177. result := false;
  178. Write('longbool OR longbool test...');
  179. lb1 := true;
  180. lb2 := false;
  181. if lb1 or lb2 then
  182. result := true;
  183. if lb2 then
  184. result := false;
  185. lb1 := false;
  186. lb2 := false;
  187. if lb1 or lb2 then
  188. result := false;
  189. lb1 := lb1 or lb2;
  190. if lb1 then
  191. result := false;
  192. if lb1 or FALSE then
  193. result := false;
  194. lb1 := true;
  195. lb2 := true;
  196. if lb1 or lb2 then
  197. begin
  198. if result then
  199. WriteLn('Success.')
  200. else
  201. Fail;
  202. end
  203. else
  204. Fail;
  205. end;
  206. Procedure BoolTestXor;
  207. var
  208. bb1, bb2: boolean;
  209. wb1, wb2: wordbool;
  210. lb1, lb2: longbool;
  211. result : boolean;
  212. begin
  213. result := false;
  214. { BOOLEAN XOR BOOLEAN }
  215. Write('boolean XOR boolean test...');
  216. bb1 := true;
  217. bb2 := false;
  218. if bb1 xor bb2 then
  219. result := true;
  220. bb1 := false;
  221. bb2 := false;
  222. if bb1 xor bb2 then
  223. result := false;
  224. bb1 := bb1 xor bb2;
  225. if bb1 then
  226. result := false;
  227. if bb1 xor FALSE then
  228. result := false;
  229. bb1 := true;
  230. bb2 := true;
  231. if bb1 xor bb2 then
  232. begin
  233. Fail;
  234. end
  235. else
  236. begin
  237. if result then
  238. WriteLn('Success.')
  239. else
  240. Fail;
  241. end;
  242. { WORDBOOL XOR WORDBOOL }
  243. result := false;
  244. Write('wordbool XOR wordbool test...');
  245. wb1 := true;
  246. wb2 := false;
  247. if wb1 xor wb2 then
  248. result := true;
  249. wb1 := false;
  250. wb2 := false;
  251. if wb1 xor wb2 then
  252. result := false;
  253. wb1 := wb1 xor wb2;
  254. if wb1 then
  255. result := false;
  256. if wb1 xor FALSE then
  257. result := false;
  258. wb1 := true;
  259. wb2 := true;
  260. if wb1 xor wb2 then
  261. begin
  262. Fail;
  263. end
  264. else
  265. begin
  266. if result then
  267. WriteLn('Success.')
  268. else
  269. Fail;
  270. end;
  271. { LONGBOOL XOR LONGBOOL }
  272. result := false;
  273. Write('longbool XOR longbool test...');
  274. lb1 := true;
  275. lb2 := false;
  276. if lb1 xor lb2 then
  277. result := true;
  278. if lb2 then
  279. result := false;
  280. lb1 := false;
  281. lb2 := false;
  282. if lb1 xor lb2 then
  283. result := false;
  284. lb1 := lb1 xor lb2;
  285. if lb1 then
  286. result := false;
  287. if lb1 xor FALSE then
  288. result := false;
  289. lb1 := true;
  290. lb2 := true;
  291. if lb1 xor lb2 then
  292. begin
  293. Fail;
  294. end
  295. else
  296. begin
  297. if result then
  298. WriteLn('Success.')
  299. else
  300. Fail;
  301. end;
  302. end;
  303. Procedure BoolTestEqual;
  304. var
  305. bb1, bb2, bb3: boolean;
  306. wb1, wb2, wb3: wordbool;
  307. lb1, lb2, lb3: longbool;
  308. result : boolean;
  309. values : longint;
  310. Begin
  311. values := $02020202;
  312. { BOOLEAN = BOOLEAN }
  313. result := true;
  314. Write('boolean = boolean test...');
  315. bb1 := true;
  316. bb2 := true;
  317. bb3 := false;
  318. bb1 := (bb1 = bb2) and (bb2 and false);
  319. if bb1 then
  320. result := false;
  321. bb1 := true;
  322. bb2 := true;
  323. bb3 := false;
  324. bb1 := (bb1 = bb2) and (bb2 and true);
  325. if not bb1 then
  326. result := false;
  327. if bb1 = bb2 then
  328. begin
  329. if result then
  330. WriteLn('Success.')
  331. else
  332. Fail;
  333. end
  334. else
  335. Fail;
  336. { WORDBOOL = WORDBOOL }
  337. result := true;
  338. Write('wordbool = wordbool test...');
  339. wb1 := true;
  340. wb2 := true;
  341. wb3 := false;
  342. wb1 := (wb1 = wb2) and (wb2 and false);
  343. if wb1 then
  344. result := false;
  345. wb1 := true;
  346. wb2 := true;
  347. wb3 := false;
  348. wb1 := (wb1 = wb2) and (wb2 and true);
  349. if not wb1 then
  350. result := false;
  351. if wb1 = wb2 then
  352. begin
  353. if result then
  354. WriteLn('Success.')
  355. else
  356. Fail;
  357. end
  358. else
  359. Fail;
  360. Write('wordbool conversion to boolean...');
  361. result := TRUE;
  362. move(values,lb1,sizeof(lb1));
  363. if lb1 <> TRUE then
  364. result := false;
  365. if result then
  366. WriteLn('Success.')
  367. else
  368. Fail;
  369. { LONGBOOL = LONGBOOL }
  370. result := true;
  371. Write('longbool = longbool test...');
  372. lb1 := true;
  373. lb2 := true;
  374. lb3 := false;
  375. lb1 := (lb1 = lb2) and (lb2 and false);
  376. if lb1 then
  377. result := false;
  378. lb1 := true;
  379. lb2 := true;
  380. lb3 := false;
  381. lb1 := (lb1 = lb2) and (lb2 and true);
  382. if not lb1 then
  383. result := false;
  384. if lb1 = lb2 then
  385. begin
  386. if result then
  387. WriteLn('Success.')
  388. else
  389. Fail;
  390. end
  391. else
  392. Fail;
  393. Write('longbool conversion to boolean...');
  394. result := TRUE;
  395. move(values,lb1,sizeof(lb1));
  396. if lb1 <> TRUE then
  397. result := false;
  398. if result then
  399. WriteLn('Success.')
  400. else
  401. Fail;
  402. end;
  403. Procedure BoolTestNotEqual;
  404. var
  405. bb1, bb2, bb3: boolean;
  406. wb1, wb2, wb3: wordbool;
  407. lb1, lb2, lb3: longbool;
  408. result : boolean;
  409. Begin
  410. { BOOLEAN <> BOOLEAN }
  411. result := true;
  412. Write('boolean <> boolean test...');
  413. bb1 := true;
  414. bb2 := true;
  415. bb3 := false;
  416. bb1 := (bb1 <> bb2) and (bb2 <> false);
  417. if bb1 then
  418. result := false;
  419. bb1 := true;
  420. bb2 := true;
  421. bb3 := false;
  422. bb1 := (bb1 <> bb2) and (bb2 <> true);
  423. if bb1 then
  424. result := false;
  425. bb1 := false;
  426. bb2 := false;
  427. if bb1 <> bb2 then
  428. begin
  429. Fail;
  430. end
  431. else
  432. begin
  433. if result then
  434. WriteLn('Success.')
  435. else
  436. Fail;
  437. end;
  438. { WORDBOOL <> WORDBOOL }
  439. result := true;
  440. Write('wordbool <> wordbool test...');
  441. wb1 := true;
  442. wb2 := true;
  443. wb3 := false;
  444. wb1 := (wb1 <> wb2) and (wb2 <> false);
  445. if wb1 then
  446. result := false;
  447. wb1 := true;
  448. wb2 := true;
  449. wb3 := false;
  450. wb1 := (wb1 <> wb2) and (wb2 <> true);
  451. if wb1 then
  452. result := false;
  453. wb1 := false;
  454. wb2 := false;
  455. if wb1 <> wb2 then
  456. begin
  457. Fail;
  458. end
  459. else
  460. begin
  461. if result then
  462. WriteLn('Success.')
  463. else
  464. Fail;
  465. end;
  466. { LONGBOOL <> LONGBOOL }
  467. result := true;
  468. Write('longbool <> longbool test...');
  469. lb1 := true;
  470. lb2 := true;
  471. lb3 := false;
  472. lb1 := (lb1 <> lb2) and (lb2 <> false);
  473. if lb1 then
  474. result := false;
  475. lb1 := true;
  476. lb2 := true;
  477. lb3 := false;
  478. lb1 := (lb1 <> lb2) and (lb2 <> true);
  479. if lb1 then
  480. result := false;
  481. lb1 := false;
  482. lb2 := false;
  483. if lb1 <> lb2 then
  484. begin
  485. Fail;
  486. end
  487. else
  488. begin
  489. if result then
  490. WriteLn('Success.')
  491. else
  492. Fail;
  493. end;
  494. end;
  495. Procedure BoolLessThen;
  496. var
  497. bb1, bb2: boolean;
  498. wb1, wb2: wordbool;
  499. lb1, lb2: longbool;
  500. Begin
  501. {!!!!!!!!!!!}
  502. end;
  503. Procedure BoolGreaterThen;
  504. var
  505. bb1, bb2: boolean;
  506. wb1, wb2: wordbool;
  507. lb1, lb2: longbool;
  508. Begin
  509. {!!!!!!!!!!!!}
  510. End;
  511. Begin
  512. BoolTestAnd;
  513. BoolTestOr;
  514. BoolTestXor;
  515. BoolTestEqual;
  516. BoolTestNotEqual;
  517. end.