Skip to content

Commit

Permalink
Add tests for the ternary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMertes committed Jan 17, 2024
1 parent deea7c2 commit a650673
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions prg/chkint.sd7
Original file line number Diff line number Diff line change
Expand Up @@ -33018,6 +33018,15 @@ const proc: check_lowestSetBit is func
end func;


const func boolean: decrementAndCheck (inout integer: number) is func
result
var boolean: ok is FALSE;
begin
decr(number);
ok := number > 0;
end func;


const proc: check_ternary is func
local
var boolean: okay is TRUE;
Expand Down Expand Up @@ -33066,6 +33075,7 @@ const proc: check_ternary is func
okay := FALSE;
end if;

ok := TRUE;
argument := 255; number := argument < 255 ? argument : 255; ok := ok and number = 255;
argument := 256; number := argument < 255 ? argument : 255; ok := ok and number = 255;
argument := 127; number := argument < 128 ? 128 : argument; ok := ok and number = 128;
Expand Down Expand Up @@ -33107,6 +33117,7 @@ const proc: check_ternary is func
okay := FALSE;
end if;

ok := TRUE;
argument := 255; number := (argument < 255 ? argument : 255) * 256; ok := ok and number = 65280;
argument := 256; number := (argument < 255 ? argument : 255) * 256; ok := ok and number = 65280;
argument := 127; number := (argument < 128 ? 128 : argument) * 256; ok := ok and number = 32768;
Expand Down Expand Up @@ -33148,6 +33159,7 @@ const proc: check_ternary is func
okay := FALSE;
end if;

ok := TRUE;
argument := 127; number := (argument < 128 ? 128 : (argument > 255 ? 255 : argument)) * 256; ok := ok and number = 32768;
argument := 128; number := (argument < 128 ? 128 : (argument > 255 ? 255 : argument)) * 256; ok := ok and number = 32768;
argument := 255; number := (argument < 128 ? 128 : (argument > 255 ? 255 : argument)) * 256; ok := ok and number = 65280;
Expand Down Expand Up @@ -33193,6 +33205,7 @@ const proc: check_ternary is func
okay := FALSE;
end if;

ok := TRUE;
argument := 127; number := (argument <= 128 ? 128 : (argument >= 255 ? 255 : argument)) * 256; ok := ok and number = 32768;
argument := 128; number := (argument <= 128 ? 128 : (argument >= 255 ? 255 : argument)) * 256; ok := ok and number = 32768;
argument := 255; number := (argument <= 128 ? 128 : (argument >= 255 ? 255 : argument)) * 256; ok := ok and number = 65280;
Expand Down Expand Up @@ -33238,6 +33251,16 @@ const proc: check_ternary is func
okay := FALSE;
end if;

ok := TRUE;
argument := 1; number := decrementAndCheck(argument) ? succ(argument) : argument; ok := ok and number = 0;
argument := 2; number := decrementAndCheck(argument) ? argument : succ(argument); ok := ok and number = 1;
argument := 3; number := decrementAndCheck(argument) ? argument : number; ok := ok and number = 2;

if not ok then
writeln(" ***** The ternary operator ? : does not work correctly. (7)");
okay := FALSE;
end if;

if okay then
writeln("The ternary operator ? : works correctly for integer.");
else
Expand Down

0 comments on commit a650673

Please sign in to comment.