(* MODULE: Test Vector
   AUTHOR: Sara Kennedy
   Last Modified: 11-OCT-02
   
   INTERFACE:
	MODULE TestVector;
	END TestVector.
*)

MODULE TestVector;

IMPORT Vector, Out, Math;

(* This Procedure formats the printing of the Cartesian and Polar Vectors to the screen *)

PROCEDURE PrintResult();

VAR x, y, magnitude, theta: REAL; (* Local Variables *)

BEGIN
	x := Vector.XCoordinate();
	y := Vector.YCoordinate();
	magnitude := Vector.Magnitude();
	theta := Vector.Angle();

	Out.String("Cartesian Coordinates: ("); 
	Out.Real(x); 
	Out.String(", "); 
	Out.Real(y); 
	Out.String("). "); 

	Out.String("Polar Coordinates: ("); 
	Out.Real(magnitude); 
	Out.String(", "); 
	Out.Real(theta); 
	Out.String(").");
	Out.Ln; Out.Ln;
END PrintResult;

(* The purpose of this function is to convert the SHORTINT Function to a Vector Interface procedure.
   It then calls the mutator function, which performs an operation.  The PrintResult() procedure is then
   called to print out each of the selectors in each test case *)

PROCEDURE Test(Function: SHORTINT; value: REAL);
BEGIN
	IF (Function = 1) THEN
		Out.String("SetXCoordinate(");
		Out.Real(value);
		Out.String(")"); Out.Ln;
		Vector.SetXCoordinate(value);
	ELSIF (Function = 2) THEN
		Out.String("SetYCoordinate(");
		Out.Real(value);
		Out.String(")"); Out.Ln;
		Vector.SetYCoordinate(value);
	ELSIF (Function = 3) THEN
		Out.String("SetMagnitude(");
		Out.Real(value);
		Out.String(")"); Out.Ln;
		Vector.SetMagnitude(value);
	ELSIF (Function = 4) THEN
		Out.String("SetAngle(");
		Out.Real(value);
		Out.String(")"); Out.Ln;
		Vector.SetAngle(value);
	ELSIF (Function = 5) THEN
		Out.String("Mul(");
		Out.Real(value);
		Out.String(")"); Out.Ln;
		Vector.Mul(value);
	END;
	PrintResult();
END Test;


(* The Testing Code.  This is the part of the code where the input values are kept.
   In each line of code Test(X, Y) will test Mutator function X with the value Y. 
   ** No Error checking has been done yet in this program.  The implementation would include
   an additional 4 variables in each Test call and then comparisons would be made. *)	

BEGIN
	PrintResult();

	Test(1, 2);
	Test(4, Math.pi/4);
	Test(2, 4);
	Test(3, 10);
	Test(5, 0.5);
	Test(1, 10);
	Test(2, 10);
	Test(3, 0);
	Test(4, Math.pi/6);
	Test(3, -4);
	Test(5, 3.0);
	Test(2, Math.Sqrt(2));
	Test(4, 0);
	Test(4, 10);
	Test(4, Math.pi/2);
	Test(5, -1);

END TestVector.
