(*

Title: T(*

Title: Test the Fourth lab
Author: Huan Gao
Revised: 24-Oct-2002
Revised again: 07-Nov-2002 for lab 4


Description: This module implements the simple interactive way to
             to test lab 3, now it is changed to lab 4. Most of them
             are kept same, except adding a menu to print the current
             linked list and add a new procedure "print linked list"
*)

MODULE Testlab4;

IMPORT In,Out,Vectors;

PROCEDURE ScreenDisplay;
BEGIN
    Out.String("This is a test program for lab 3 of 2A04");
    Out.Ln;

    Out.String("a: Test Get Vector.");
    Out.Ln;

    Out.String("b: Test Vector Addition");
    Out.Ln;

    Out.String("c: Test vector multiplication");
    Out.Ln;

    Out.String("d: Print the current linked list");
    Out.Ln;

    Out.String("q: Quit from this test program");
    Out.Ln;

END ScreenDisplay;


PROCEDURE  KeyboardInput;
VAR
    ch : CHAR;
    temp1,temp2,sumtemp1temp2,multemp1:Vectors.Vector;
    input1x,input1y,input2x,input2y,multipliednumber : REAL;
    tempx,tempy : REAL;

BEGIN
    WHILE (1>0) DO
        In.Char(ch);
        IF (ch = "a") THEN
             Out.String("Now we are testing getting the vector");
             Out.Ln;

             Out.String("Please input x value of the vector:");
             In.Real(input1x);
             Out.String("Please input y value of the vector:");
             In.Real(input1y);

             Out.String("So the original vector:(");
             Out.Real(input1x);
             Out.String(",");
             Out.Real(input1y);
             Out.String(")");
             Out.Ln;

             Out.String("We call GetVec method to get or create the vector.");
             Out.Ln;
             temp1 := Vectors.GetVec(input1x,input1y);
             Out.String("We call XVal method and YVal method to show x and y value");
             Out.Ln;
             Out.String("The expected vector is ( ");
             tempx := Vectors.XVal(temp1);
             tempy := Vectors.YVal(temp1);
             Out.Real(tempx);
             Out.String(",");
             Out.Real(tempy);
             Out.String(")");
             Out.Ln;
             Out.Ln;
             Out.Ln;

             Out.String("Please input a:GetVec--b:addition--c:multiplication--d:print the current list--q:quit");
             Out.Ln;
             Out.Ln
        ELSIF (ch = "b") THEN

             Out.String("We are testing the addition of two vectors");
             Out.Ln;

             Out.String("Please input x of the first vector:");
             In.Real(input1x);
             Out.String("Please input y of the first vector:");
             In.Real(input1y);

             Out.String("Please input x of the second vector:");
             In.Real(input2x);
             Out.String("Please input y of the second vector:");
             In.Real(input2y);
             Out.Ln;

             Out.String("The original first vector:(");
             Out.Real(input1x);
             Out.String(",");
             Out.Real(input1y);
             Out.String(")");
             Out.Ln;

             Out.String("The original second vector:(");
             Out.Real(input2x);
             Out.String(",");
             Out.Real(input2y);
             Out.String(")");
             Out.Ln;

             temp1 := Vectors.GetVec(input1x,input1y);
             temp2 := Vectors.GetVec(input2x,input2y);
             sumtemp1temp2 := Vectors.Add(temp1,temp2);
             tempx := Vectors.XVal(sumtemp1temp2);
             tempy := Vectors.YVal(sumtemp1temp2);

             Out.String("The summation vector of original first and second vectors:(");

             Out.Real(tempx);
             Out.String(",");

             Out.Real(tempy);
             Out.String(")");
             Out.Ln;
             Out.Ln;
             Out.Ln;

             Out.String("Please input a:GetVec--b:addition--c:multiplication--d:print the current list--q:quit");
             Out.Ln;
             Out.Ln
        ELSIF (ch = "c") THEN

             Out.String("We are testing multiplication ");
             Out.Ln;
             Out.String("Please input x of the original vector:");
             In.Real(input1x);
             Out.String("Please input y of the original vector:");
             In.Real(input1y);
             Out.String("Please input the multiplied real number:");
             In.Real(multipliednumber);
             Out.Ln;

             Out.String("The original first vector:(");
             Out.Real(input1x);
             Out.String(",");
             Out.Real(input1y);
             Out.String(")");
             Out.Ln;
             Out.String("This vector is multiplied by ");
             Out.Real(multipliednumber);
             Out.Ln;

             temp1 := Vectors.GetVec(input1x,input1y);
             multemp1 := Vectors.Mul(multipliednumber, temp1);
             tempx := Vectors.XVal(multemp1);
             tempy := Vectors.YVal(multemp1);

             Out.String("The final result is ");
             Out.String("(");
             Out.Real(tempx);
             Out.String(",");
             Out.Real(tempy);
             Out.String(")");
             Out.Ln;
             Out.Ln;
             Out.Ln;

             Out.String("Please input a:GetVec--b:addition--c:multiplication--d:print the current list--q:quit");
             Out.Ln;
             Out.Ln
        ELSIF (ch = "d") THEN (* add menu d for the lab 4 *)
             Print();
             Out.Ln;
         Out.Ln;

         Out.String("Please input a:GetVec--b:addition--c:multiplication--d:print the current list--q:quit");
         Out.Ln;
         Out.Ln
        ELSIF (ch = "q") THEN
             Out.String("Thank you for using this test program");
             Out.Ln;
             HALT(1);
        END;


    END;

END KeyboardInput;

PROCEDURE Print();
VAR Temp : Vectors.Vector;
BEGIN
    Temp := Vectors.Head;
    WHILE (Temp # NIL) DO
        Out.Real(Vectors.XVal(Temp));
        Out.String(",");
        Out.Real(Vectors.YVal(Temp));
        Out.Ln;
        Temp := Temp^.PointToNext;
    END;
END Print;

BEGIN
    ScreenDisplay;
    KeyboardInput;
END Testlab4.
