/*

Summary:

	Unit tests in this program are for IF conditional tests.

Description:

	Testing > >= < <= = <>
	Testing unsigned Bytes

*/
program IfThenElseTest01;
var name : string := "IfThenElseTest01";
@include "common.tru"
var  
	sc, co : pointer; 			// screen and colour RAM pointers

/*--------------------------------------------------------------------------------------------

	VARIABLES FOR USE IN UNIT TESTS
	
----------------------------------------------------------------------------------------------*/

	v1, v2, v3, v4  : byte;
	i1,i2,i3,i4 : integer;

/*--------------------------------------------------------------------------------------------

	UNIT TESTS
	
----------------------------------------------------------------------------------------------*/

// when v1 is greater than v2
procedure GT1_GreaterThan_True();
begin
	v1 := 100; v2 := 50;
	text := "   GT 1:"; if v1 > v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not greater than v2
procedure GT2_GreaterThan_False();
begin
	v1 := 10; v2 := 50;
	text := "   GT 2:"; if v1 > v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is equal to v2
procedure GT3_GreaterThan_False();
begin
	v1 := 50; v2 := 50;
	text := "   GT 3:"; if v1 > v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is zero and v2 is 255
procedure GT4_GreaterThan_False();
begin
	v1 := 0; v2 := 255;
	text := "   GT 4:"; if v1 > v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is 255 and v2 is 0
procedure GT5_GreaterThan_True();
begin
	v1 := 255; v2 := 0;
	text := "   GT 5:"; if v1 > v2 then begin PASS(); end else begin FAIL(); end;
end;


// when v1 is greater than v2
procedure GTE1_GreaterEqual_True();
begin
	v1 := 51; v2 := 50;
	text := "  GTE 1:"; if v1 >= v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not greater than v2
procedure GTE2_GreaterThan_False();
begin
	v1 := 49; v2 := 50;
	text := "  GTE 2:"; if v1 >= v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is equal to v2
procedure GTE3_GreaterThan_True();
begin
	v1 := 50; v2 := 50;
	text := "  GTE 3:"; if v1 >= v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is zero and v2 is 255
procedure GTE4_GreaterThan_False();
begin
	v1 := 0; v2 := 255;
	text := "  GTE 4:"; if v1 >= v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is 255 and v2 is 0
procedure GTE5_GreaterThan_True();
begin
	v1 := 255; v2 := 0;
	text := "  GTE 5:"; if v1 >= v2 then begin PASS(); end else begin FAIL(); end;
end;


// when v1 is less than v2
procedure LT1_LessThan_True();
begin
	v1 := 49; v2 := 50;
	text := "   LT 1:"; if v1 < v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not less than v2
procedure LT2_LessThan_False();
begin
	v1 := 51; v2 := 50;
	text := "   LT 2:"; if v1 < v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is equal to v2
procedure LT3_LessThan_False();
begin
	v1 := 50; v2 := 50;
	text := "   LT 3:"; if v1 < v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is zero and v2 is 255
procedure LT4_LessThan_True();
begin
	v1 := 0; v2 := 255;
	text := "   LT 4:"; if v1 < v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is 255 and v2 is 0
procedure LT5_LessThan_False();
begin
	v1 := 255; v2 := 0;
	text := "   LT 5:"; if v1 < v2 then begin FAIL(); end else begin PASS(); end;
end;


// when v1 is less than v2
procedure LTE1_LessEqual_True();
begin
	v1 := 49; v2 := 50;
	text := "  LTE 1:"; if v1 <= v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not less or equal to v2
procedure LTE2_LessThan_False();
begin
	v1 := 51; v2 := 50;
	text := "  LTE 2:"; if v1 <= v2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is equal to v2
procedure LTE3_LessThan_True();
begin
	v1 := 50; v2 := 50;
	text := "  LTE 3:"; if v1 <= v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is zero and v2 is 255
procedure LTE4_LessThan_True();
begin
	v1 := 0; v2 := 255;
	text := "  LTE 4:"; if v1 <= v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is 255 and v2 is 0
procedure LTE5_LessThan_False();
begin
	v1 := 255; v2 := 0;
	text := "  LTE 5:"; if v1 <= v2 then begin FAIL(); end else begin PASS(); end;
end;


// when v1 is equal to v2
procedure EQ1_EqualTo_True();
begin
	v1 := 255; v2 := 255;
	text := "   EQ 1:"; if v1 = v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not equal to v2
procedure EQ2_EqualTo_False();
begin
	v1 := 0; v2 := 255;
	text := "   EQ 2:"; if v1 = v2 then begin FAIL(); end else begin PASS(); end;
end;


// when v1 is not equal to v2
procedure NEQ1_NotEqualTo_True();
begin
	v1 := 5; v2 := 6;
	text := "  NEQ 1:"; if v1 <> v2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not equal to v2
procedure NEQ2_NotEqualTo_False();
begin
	v1 := 5; v2 := 5;
	text := "  NEQ 2:"; if v1 <> v2 then begin FAIL(); end else begin PASS(); end;
end;


procedure Advanced1();
begin
	v1 := 5; v2 := 5;
	v3:=5; v4:=4;
	
	text := "  ADV 1:";if (v1 >= v2 and v3<>5) then begin FAIL(); end else begin PASS(); end;
end;


procedure Advanced2();
begin
	v1 := 5; v2 := 5;
	v3:=5; v4:=4;
	text := "  ADV 2:"; if (v1 = v2 and (v3<>5 or v4=4)) then begin PASS(); end else begin FAIL(); end;
end;





// when v1 is greater than v2
procedure IGT1_GreaterThan_True();
begin
	i1 := 1000; i2 := 500;
	text := "   GI 1:"; if i1 > i2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not greater than v2
procedure IGT2_GreaterThan_False();
begin
	i1 := 100; i2 := 500;
	text := "   GI 2:"; if i1 > i2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is equal to v2
procedure IGT3_GreaterThan_False();
begin
	i1 := 500; i2 := 500;
	text := "   GI 3:"; if i1 > i2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is zero and v2 is 255
procedure IGT4_GreaterThan_False();
begin
	i1 := 0; i2 := 2550;
	text := "   GI 4:"; if i1 > i2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is 255 and v2 is 0
procedure IGT5_GreaterThan_True();
begin
	i1 := 2550; i2 := 0;
	text := "   GI 5:"; if i1 > i2 then begin PASS(); end else begin FAIL(); end;
end;


// when v1 is greater than v2
procedure IGTE1_GreaterEqual_True();
begin
	i1 := 510; i2 := 500;
	text := "  GIE 1:"; if i1 >= i2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is not greater than v2
procedure IGTE2_GreaterThan_False();
begin
	i1 := 490; i2 := 500;
	text := "  GIE 2:"; if i1 >= i2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is equal to v2
procedure IGTE3_GreaterThan_True();
begin
	i1 := 500; i2 := 500;
	text := "  GIE 3:"; if i1 >= i2 then begin PASS(); end else begin FAIL(); end;
end;

// when v1 is zero and v2 is 255
procedure IGTE4_GreaterThan_False();
begin
	i1 := 0; i2 := 2550;
	text := "  GIE 4:"; if i1 >= i2 then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is 255 and v2 is 0
procedure IGTE5_GreaterThan_True();
begin
	i1 := 2550; i2 := 513;
	text := "  GIE 5:"; if i1 >= i2 then begin PASS(); end else begin FAIL(); end;
end;


// when v1 is 255 and v2 is 0
procedure AdvancedI1();
begin
	i1 := 5000; i2 := 4000; i3:=3000;
	text := "   AI 1:"; if (i1 >= i2 and i3=3000)  then begin PASS(); end else begin FAIL(); end;
end;


// when v1 is 255 and v2 is 0
procedure AdvancedI2();
begin
	i1 := 5000; i2 := 5000; i3:=3000;
	text := "   AI 2:"; if (i1 > i2 or i3=5000) then begin FAIL(); end else begin PASS(); end;
end;

// when v1 is 255 and v2 is 0
procedure AdvancedI3();
begin
	i1 := 5000; i2 := 5000; i3:=3000;
	text := "   AI 3:"; if (i1 = i2 or (i3=3000 and i1>=5000)) then begin PASS(); end else begin FAIL(); end;
end;


// when v1 is 255 and v2 is 0
procedure BranchSize1();
begin
	text := "   B1:"; if (7 > 5)  then begin PASS(); nop(120);end else begin FAIL(); end;
end;

// when v1 is 255 and v2 is 0
procedure AdvancedI4();
begin
	i1:=$600;
	v1:=$F0;	
	text := "   AI:"; asm(";bummer");if ((i1 > $501) and (i1 < $551)) then FAIL() else PASS();
//	text := "   AI:"; asm(";bummer");if ((i1 > $551)) then FAIL() else PASS();
//	text := "   AI:"; asm(";bummer");if (v1 > $20 and v1 < $50) then FAIL() else PASS();
end;



//--------------------------------------------------------------------------------------------
/* MAIN PROGRAM */
procedure RunTests();
begin
	// Greater than conditional tests 
	GT1_GreaterThan_True();
	GT2_GreaterThan_False();
	GT3_GreaterThan_False();
	GT4_GreaterThan_False();
	GT5_GreaterThan_True();
	
	// Greater than or equal to conditional tests
	GTE1_GreaterEqual_True();
	GTE2_GreaterThan_False();
	GTE3_GreaterThan_True();
	GTE4_GreaterThan_False();
	GTE5_GreaterThan_True();

	// Less than conditional tests
	LT1_LessThan_True();
	LT2_LessThan_False();
	LT3_LessThan_False();
	LT4_LessThan_True();
	LT5_LessThan_False();

	// Less than or equal to conditional tests
	LTE1_LessEqual_True();
	LTE2_LessThan_False();
	LTE3_LessThan_True();
	LTE4_LessThan_True();
	LTE5_LessThan_False();
	
	// Equal to conditional tests
	EQ1_EqualTo_True();
	EQ2_EqualTo_False();

	// Not Equal to conditional tests
	NEQ1_NotEqualTo_True();
	NEQ2_NotEqualTo_False();

	Advanced1();
	Advanced2();




	// Greater than conditional tests 
	IGT1_GreaterThan_True();
	IGT2_GreaterThan_False();
	IGT3_GreaterThan_False();
	IGT4_GreaterThan_False();
	IGT5_GreaterThan_True();
	
	// Greater than or equal to conditional tests
	IGTE1_GreaterEqual_True();
	IGTE2_GreaterThan_False();
	IGTE3_GreaterThan_True();
	IGTE4_GreaterThan_False();
	IGTE5_GreaterThan_True();

	AdvancedI1();
	AdvancedI2();
	AdvancedI3();
	AdvancedI4();

//	BranchSize1();
end;

begin
	Main();
	Loop();
end.
