123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566 |
- { Program to test Code generator secondadd() }
- { with boolean values. }
- { FUNCTIONAL PRE-REQUISITES: }
- { - assignments function correctly. }
- { - if statements function correctly. }
- { - subroutine calls function correctly. }
- Program TAddBool;
- {$IFDEF VER70}
- TYPE
- cardinal = longint;
- {$ENDIF}
- procedure fail;
- begin
- WriteLn('Failed!');
- halt(1);
- end;
- { ---------------------------- BOOLEAN TEST ----------------------------- }
- { secondadd() }
- { ----------------------------------------------------------------------- }
- procedure BoolTestAnd;
- var
- bb1, bb2: boolean;
- wb1, wb2: wordbool;
- lb1, lb2: longbool;
- result : boolean;
- begin
- result := true;
- { BOOLEAN AND BOOLEAN }
- Write('boolean AND boolean test...');
- bb1 := true;
- bb2 := false;
- if bb1 and bb2 then
- result := false;
- if bb2 then
- result := false;
- bb1 := false;
- bb2 := false;
- if bb1 and bb2 then
- result := false;
- bb1 := bb1 and bb2;
- if bb1 then
- result := false;
- if bb1 and FALSE then
- result := false;
- bb1 := true;
- bb2 := true;
- if bb1 and bb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- { WORDBOOL AND WORDBOOL }
- result := true;
- Write('wordbool AND wordbool test...');
- wb1 := true;
- wb2 := false;
- if wb1 and wb2 then
- result := false;
- if wb2 then
- result := false;
- wb1 := false;
- wb2 := false;
- if wb1 and wb2 then
- result := false;
- wb1 := wb1 and wb2;
- if wb1 then
- result := false;
- if wb1 and FALSE then
- result := false;
- wb1 := true;
- wb2 := true;
- if wb1 and wb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- { LONGBOOL AND LONGBOOL }
- result := true;
- Write('longbool AND longbool test...');
- lb1 := true;
- lb2 := false;
- if lb1 and lb2 then
- result := false;
- if lb2 then
- result := false;
- lb1 := false;
- lb2 := false;
- if lb1 and lb2 then
- result := false;
- lb1 := lb1 and lb2;
- if lb1 then
- result := false;
- if lb1 and FALSE then
- result := false;
- lb1 := true;
- lb2 := true;
- if lb1 and lb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- end;
- procedure BoolTestOr;
- var
- bb1, bb2: boolean;
- wb1, wb2: wordbool;
- lb1, lb2: longbool;
- result : boolean;
- begin
- result := false;
- { BOOLEAN AND BOOLEAN }
- Write('boolean OR boolean test...');
- bb1 := true;
- bb2 := false;
- if bb1 or bb2 then
- result := true;
- bb1 := false;
- bb2 := false;
- if bb1 or bb2 then
- result := false;
- bb1 := bb1 or bb2;
- if bb1 then
- result := false;
- if bb1 or FALSE then
- result := false;
- bb1 := true;
- bb2 := true;
- if bb1 or bb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- { WORDBOOL AND WORDBOOL }
- result := false;
- Write('wordbool OR wordbool test...');
- wb1 := true;
- wb2 := false;
- if wb1 or wb2 then
- result := true;
- wb1 := false;
- wb2 := false;
- if wb1 or wb2 then
- result := false;
- wb1 := wb1 or wb2;
- if wb1 then
- result := false;
- if wb1 or FALSE then
- result := false;
- wb1 := true;
- wb2 := true;
- if wb1 or wb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- { LONGBOOL AND LONGBOOL }
- result := false;
- Write('longbool OR longbool test...');
- lb1 := true;
- lb2 := false;
- if lb1 or lb2 then
- result := true;
- if lb2 then
- result := false;
- lb1 := false;
- lb2 := false;
- if lb1 or lb2 then
- result := false;
- lb1 := lb1 or lb2;
- if lb1 then
- result := false;
- if lb1 or FALSE then
- result := false;
- lb1 := true;
- lb2 := true;
- if lb1 or lb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- end;
- Procedure BoolTestXor;
- var
- bb1, bb2: boolean;
- wb1, wb2: wordbool;
- lb1, lb2: longbool;
- result : boolean;
- begin
- result := false;
- { BOOLEAN XOR BOOLEAN }
- Write('boolean XOR boolean test...');
- bb1 := true;
- bb2 := false;
- if bb1 xor bb2 then
- result := true;
- bb1 := false;
- bb2 := false;
- if bb1 xor bb2 then
- result := false;
- bb1 := bb1 xor bb2;
- if bb1 then
- result := false;
- if bb1 xor FALSE then
- result := false;
- bb1 := true;
- bb2 := true;
- if bb1 xor bb2 then
- begin
- Fail;
- end
- else
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end;
- { WORDBOOL XOR WORDBOOL }
- result := false;
- Write('wordbool XOR wordbool test...');
- wb1 := true;
- wb2 := false;
- if wb1 xor wb2 then
- result := true;
- wb1 := false;
- wb2 := false;
- if wb1 xor wb2 then
- result := false;
- wb1 := wb1 xor wb2;
- if wb1 then
- result := false;
- if wb1 xor FALSE then
- result := false;
- wb1 := true;
- wb2 := true;
- if wb1 xor wb2 then
- begin
- Fail;
- end
- else
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end;
- { LONGBOOL XOR LONGBOOL }
- result := false;
- Write('longbool XOR longbool test...');
- lb1 := true;
- lb2 := false;
- if lb1 xor lb2 then
- result := true;
- if lb2 then
- result := false;
- lb1 := false;
- lb2 := false;
- if lb1 xor lb2 then
- result := false;
- lb1 := lb1 xor lb2;
- if lb1 then
- result := false;
- if lb1 xor FALSE then
- result := false;
- lb1 := true;
- lb2 := true;
- if lb1 xor lb2 then
- begin
- Fail;
- end
- else
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end;
- end;
- Procedure BoolTestEqual;
- var
- bb1, bb2, bb3: boolean;
- wb1, wb2, wb3: wordbool;
- lb1, lb2, lb3: longbool;
- result : boolean;
- values : longint;
- Begin
- values := $02020202;
- { BOOLEAN = BOOLEAN }
- result := true;
- Write('boolean = boolean test...');
- bb1 := true;
- bb2 := true;
- bb3 := false;
- bb1 := (bb1 = bb2) and (bb2 and false);
- if bb1 then
- result := false;
- bb1 := true;
- bb2 := true;
- bb3 := false;
- bb1 := (bb1 = bb2) and (bb2 and true);
- if not bb1 then
- result := false;
- if bb1 = bb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- { WORDBOOL = WORDBOOL }
- result := true;
- Write('wordbool = wordbool test...');
- wb1 := true;
- wb2 := true;
- wb3 := false;
- wb1 := (wb1 = wb2) and (wb2 and false);
- if wb1 then
- result := false;
- wb1 := true;
- wb2 := true;
- wb3 := false;
- wb1 := (wb1 = wb2) and (wb2 and true);
- if not wb1 then
- result := false;
- if wb1 = wb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- Write('wordbool conversion to boolean...');
- result := TRUE;
- move(values,lb1,sizeof(lb1));
- if lb1 <> TRUE then
- result := false;
- if result then
- WriteLn('Success.')
- else
- Fail;
- { LONGBOOL = LONGBOOL }
- result := true;
- Write('longbool = longbool test...');
- lb1 := true;
- lb2 := true;
- lb3 := false;
- lb1 := (lb1 = lb2) and (lb2 and false);
- if lb1 then
- result := false;
- lb1 := true;
- lb2 := true;
- lb3 := false;
- lb1 := (lb1 = lb2) and (lb2 and true);
- if not lb1 then
- result := false;
- if lb1 = lb2 then
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end
- else
- Fail;
- Write('longbool conversion to boolean...');
- result := TRUE;
- move(values,lb1,sizeof(lb1));
- if lb1 <> TRUE then
- result := false;
- if result then
- WriteLn('Success.')
- else
- Fail;
- end;
- Procedure BoolTestNotEqual;
- var
- bb1, bb2, bb3: boolean;
- wb1, wb2, wb3: wordbool;
- lb1, lb2, lb3: longbool;
- result : boolean;
- Begin
- { BOOLEAN <> BOOLEAN }
- result := true;
- Write('boolean <> boolean test...');
- bb1 := true;
- bb2 := true;
- bb3 := false;
- bb1 := (bb1 <> bb2) and (bb2 <> false);
- if bb1 then
- result := false;
- bb1 := true;
- bb2 := true;
- bb3 := false;
- bb1 := (bb1 <> bb2) and (bb2 <> true);
- if bb1 then
- result := false;
- bb1 := false;
- bb2 := false;
- if bb1 <> bb2 then
- begin
- Fail;
- end
- else
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end;
- { WORDBOOL <> WORDBOOL }
- result := true;
- Write('wordbool <> wordbool test...');
- wb1 := true;
- wb2 := true;
- wb3 := false;
- wb1 := (wb1 <> wb2) and (wb2 <> false);
- if wb1 then
- result := false;
- wb1 := true;
- wb2 := true;
- wb3 := false;
- wb1 := (wb1 <> wb2) and (wb2 <> true);
- if wb1 then
- result := false;
- wb1 := false;
- wb2 := false;
- if wb1 <> wb2 then
- begin
- Fail;
- end
- else
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end;
- { LONGBOOL <> LONGBOOL }
- result := true;
- Write('longbool <> longbool test...');
- lb1 := true;
- lb2 := true;
- lb3 := false;
- lb1 := (lb1 <> lb2) and (lb2 <> false);
- if lb1 then
- result := false;
- lb1 := true;
- lb2 := true;
- lb3 := false;
- lb1 := (lb1 <> lb2) and (lb2 <> true);
- if lb1 then
- result := false;
- lb1 := false;
- lb2 := false;
- if lb1 <> lb2 then
- begin
- Fail;
- end
- else
- begin
- if result then
- WriteLn('Success.')
- else
- Fail;
- end;
- end;
- Procedure BoolLessThen;
- var
- bb1, bb2: boolean;
- wb1, wb2: wordbool;
- lb1, lb2: longbool;
- Begin
- {!!!!!!!!!!!}
- end;
- Procedure BoolGreaterThen;
- var
- bb1, bb2: boolean;
- wb1, wb2: wordbool;
- lb1, lb2: longbool;
- Begin
- {!!!!!!!!!!!!}
- End;
- Begin
- BoolTestAnd;
- BoolTestOr;
- BoolTestXor;
- BoolTestEqual;
- BoolTestNotEqual;
- end.
|