5.4. StudentInterface

(****
 * Module StudentInterface defines the basic objects and operations used by the student
 * interface. The student interface defines a student workspace which will be used to display practice and take home tests. The student also
 * uses this interface to view his graded tests after they have been made available by the instructor.
 *)
module StudentInterface;
 from QuestionModule import ClassName,Topic,Author,AverageScore,Created,Modified,LastUsed,Notes,Question,ID,Type,QuestionText,Difficulty,
              Time,CorrectAnswer,Answer;
 from TestGeneration import Test,TotalPoints,TotalTime;
 from TestAdminister import Roster;
 from StudentFile import FilePermissions;
 from StudentEdit import PreviousState;
 export FileSaveDialog, StudentWorkSpace, Text, HighlightedText, TestFile,
    FileOpenDialog, LocationAddress, StudentLogOnScreen, length, Student, StudentInfo;

 object StudentWorkSpace is
    components: t:Test and los:StudentLogOnScreen;
    operations: LogOn,OpenTest,CloseTest,ExitStudentInterface,TakeInClassTest,CheckGradedTest;
    description: (*
        The StudentWorkSpace is the work space the student uses to complete a
        test inside the student interface. It displays the operations of the
        StudentFile, StudentEdit, and StudentTests modules as menu items titled
        "File", "Edit", and "Test". The work space allows students to view,
        modify, and save test files on an individual computer with the Test
        Tool program installed.
       
    *);
 end StudentWorkSpace;

 object TestFile is
    components: fp:FilePermissions and t:Test;
    operations: OpenTest,SaveTest,SaveTestAs,CloseTest,ExitStudentInterFace,TakeHomeTest,PracticeTest;
    description: (*
        A TestFile is the file representation of a test. The StudentWorkSpace
        uses TestFile objects to open or save tests modified in the student
        interface. A TestFile must be readable and writable and can be saved
        on a computer accessible to the student.
    *);
 end TestFile;

 object Text is
    components: str:string and ps:PreviousState;
    operations: UndoChange,PasteText;
    description: (*
        A Text object is a group of one or more characters printed on a screen.
        A student uses Text to answer short answer, essay, and programming
        questions on a test. The student can only modify text used in his
        answers on a test, and the text must conform to standard ASCII.
    *);
 end Text;

 object length is integer
    description: (*
        Length is the length a string determined by how many characters are
        within a string. Characters include all ASCII characters and white
        spaces.
    *);
 end length;

 object HighlightedText is
    components: str:string and l:length;
    operations: CutText,CopyText;
    description: (*
        A HighlightedText object is a section or an entire body of text selected
        to be edited. The text can be cut, copied, erased, or replaced by another
        section or body of text. Any text that is highlighted should stand out from
        the rest of the text. The text should be bolded or be displayed in a different
        color than the rest of the text so the student can distinguish between
        highlighted and non-highlighted text.
    *);
 end HighlightedText;

 object LocationAddress is string
    operations:CheckGradedTest;
    description: (*
        A LocationAddress is an address where a student can retrieve a graded test.
        The address is given by the instructor, and the student uses the address
        in the GradedTestLocationInterface to retrieve a copy of his graded test.
        A LocationAddress can either be an IP address or a unique network address
        as a single string one to forty characters long inclusive.
    *);
 end LocationAddress;
 object Student is
    components: FirstName and LastName and un:StudentUserName and ps:StudentPassword;
    description: (*
        A student is a user with a first name of twenty-five characters or less,
        a last name of twenty-five characters or less, and a student ID of
        twenty-five characters or less. A student logs on to the student interface
        with his individual user name and password and takes a test.
    *);
 end Student;

 object FirstName is string
    description:(*The first name of the student*);
end;

 object LastName is string
    description:(*The last name of the student*);
 end;

 object StudentUserName is string
    operations: LogOn;
    description: (*
        A UserName is a unique string that is equivalent to a students Identification. The user name must match a
        user name on the roster befor the student can access
        the student interface.
     *);
 end StudentUserName;

 object StudentPassword is string
    operations: LogOn;
    description: (*
        A Password is a unique string that corresponds to the students user name. The student uses this to log on to the
        student interface.
    *);
 end StudentPassword;

 object StudentLogOnScreen is
    components: StudentUserName and StudentPassword;
    operations: LogOn;
    description: (*
        A student types in their Calpoly ID and password into the Log on screen
        to gain access to the student interface.
    *);
 end StudentLogOnScreen;

 object StudentInfo is un:StudentUserName and ps:StudentPassword
    operations: LogOn;
    description: (*
        StudentInfo comprizes of the student, his user ID and his password.
    *);
 end StudentInfo;

 operation LogOn is
    inputs: stud:Student and roster:Roster and un:StudentUserName and ps:StudentPassword;
    outputs: StudentWorkSpace;
    description: (*
        Log on the student user to the student interface. The given UserName and
        password must be unique and match only one UserName and password existing
        in the student database. The UserName component is required and must be
        sixteen characters or less. The Password is required and must be sixteen
        characters or less.
    *);
   
    precondition:
        (*
         * The user name in the input UserName is not empty, has 16 characters or
         * less, and is identical to only one user name in the student database.
         *)
        (exists (stud in roster) stud.un = un and stud.ps= ps);
    postcondition:
        (*
         * The student interface is the output if and only if the un and pswd
         * match one Student.UserName and Student.Password in the student database.
         *)
        (forall (student_info in roster)
            (student_info in roster) iff ((student_info.un = un) and (student_info.ps = ps)));
 end LogOn;

 object FileOpenDialog is
    operations: TakeHomeTest, PracticeTest;
    components: FileName and FileLocation;
    description: (*
        The FileOpenDialog is the dialog interface where a student may select only
        a test file to open into the student interface from a specific directory.
    *);
 end FileOpenDialog;

 object FileName is string
    description: (*
        A FileName is a single string that is the name of the file. The name should be unique and should
        automatically include the file extension at the end of the name.
    *);
 end FileName;

 object FileLocation is string
    description: (*
        FileLocation is the directory where the file is to be saved. The student
        must specify a directory to save the file when using the Save As
        operation defined in the StudentFile module.
    *);
 end FileLocation;

 object FileSaveDialog is
    components: FileName and FileLocation;
    operations:SaveTest,SaveTestAs;
    description: (*
        The FileSaveDialog is the dialog interface where a student may save the test
        file displayed in the student interface to a specific directory.
    *);
 end FileSaveDialog;

end StudentInterface;

(****
 *
 * Module Student File defines the operations related to opening a test, saving a test,
 * saving a test under a specific file name, and exiting the student interface. Some
 * object definitions are taken from the Calander RSL specifictations which include
 * FilePermissions, IsReadable, IsWritable, FileType, TestType, FileData, and
 * RequiresSaving.
 *
 *)
module StudentFile;

 from StudentInterface import TestFile, Test, FileSaveDialog, StudentWorkSpace, StudentLogOnScreen;
 export FilePermissions;

 object FilePermissions is
    components: ir:IsReadable and iw:IsWritable;
    operations: OpenTest;
    description: (*
        FilePermissions are permissions indicating if a file is readable and/or
        writable.
    *);
 end FilePermissions;

 object IsReadable is boolean
    operations: OpenTest;
    description: (*
        A flag indicating if a file is readable, which must be true to carry out the
        OpenTest operation.
    *);
 end IsReadable;

 object IsWritable is boolean
    operations:SaveTest, SaveTestAs;
    description: (*
        A flag indicating if a file is writable, which must be true to carry out the
        SaveTest and SaveTestAs operations.
    *);
 end IsWritable;

 object FileType is TestType
    operations: OpenTest;
    description: (*
        The type of file used by the student interface where data is of TestType
        and can be stored in a file.
    *);
 end FileType;

 object TestType is
    operations: OpenTest;
    description: (*
        File data tag that indicates if a file contains Test data made by the Test
        Tool program.
    *);
 end TestType;

 object FileData is Test
    operations: OpenTest;
    description: (*
        FileData is a representation of a Test object. When implementing FileData,
        any file data object may be used that accurately holds a Test object.
    *);
 end FileData;

 operation OpenTest is
    inputs: sw:StudentWorkSpace and tf:TestFile and permissions:FilePermissions and fd:FileData
        and ft:FileType and ir:IsReadable and tt:TestType;
    outputs: Test and sw':StudentWorkSpace;
    description: (*
        OpenTest will open a test file from a specific directory and display it in
        the student interface. The student may only open test files in the
        student interface and not any other type of file. Test files include actual
        tests and graded tests.
    *);

 precondition:
    (*
     * A test file must exist and be located in a directory that is accessible by the
     * student. The file must also be readable and the type of the file must be of type
     * test. This precondition is taken from the precondition of the FileOpen operation
     * of the Calander RSL specification.
     *)
    (exists (tf:TestFile) (tf.fp.ir));

 postcondition:
    (*
     * The test file is opened into the student interface filling in the entire
     * student interface area.
     *)
    (sw'.t = tf.t) and sw'.los = sw.los;

 end OpenTest;

 operation SaveTest is
    inputs: t:Test and fsd: FileSaveDialog and iw:IsWritable;
    outputs: tf':TestFile;
    description: (*
        SaveTest will save any changes made to the currently displayed Test in the
        student interface to the test file that contains the test. This option only
        updates the test file with the new changes that are not contained in the
        old test file and the file must be writable. The Save operation should be
        disabled when a student is taking an in class test.
    *);
   
 precondition:
    (*
     * A test file must exist and be located in a directory that is accessible by the
     * student. The Save operation is disabled if the student is taking an in class test
     * in which case IsWritable would be false.
     *)
    (exists (tf:TestFile) (tf.t = t) and (tf.fp.iw));

 postcondition:
    (*
     * Changes must have been made to the test in the student interface that are not
     * contained in the old test file.
     *)
    (tf'.t = t) and (tf'.fp.iw) and (tf'.fp.ir);
       
 end SaveTest;

 operation SaveTestAs is
    inputs: t:Test and fsd:FileSaveDialog and iw:IsWritable;
    outputs: tf':TestFile;
    description: (*
        SaveTestAs will save the test file currently displayed in the student interface
        as a new file in a specific directory. This operation can either create a new
        file with a new name or overwrite an old file that is writable with the same name.
        If overwriting a file with the same name, the student must be prompted that saving
        the test file will overwrite the old file and if he wishes to continue. When a
        student does save a file using the Save As operation, the file can only be saved
        as a test file type. The Save As operation should be disabled when the student
        is taking an in class test.
    *);

 precondition:
    (*
     * A test object must exist as an object that can be saved as a file and be displayed
     * in the student interface.
     *)
    (t != nil);

 postcondition:
    (*
     * A test file is made from the test object currently displayed in the student interface
     * under a file name of the student's choosing. The test file is saved in a directory
     * accessible by the student.
     *)
    (tf'.t = t) and (tf'.fp.ir) and (tf'.fp.iw);

 end SaveTestAs;

 object UserWantsToSave is boolean
    description: (*
        UserWantsToSave is a state that tells the student interface if the student
        wants to save the changes made to a test.
    *);
 end UserWantsToSave;

 operation CloseTest is
    inputs: t:Test and sw:StudentWorkSpace and uwts:UserWantsToSave and tf:TestFile;
    outputs: tf':TestFile, sw':StudentWorkSpace;
    description: (*
        CloseStudentInterface will close the currently opened test in the student
        interface and allow the interface to continue to run. If there is a test
        in the student interface that has been changed but not saved, a prompt will
        appear asking the student if he would like to save the changes to the test
        before closing the test. The operation is disabled if a student is taking
        an in class test.

 precondition:
    (*
     * The test is currently opened at this moment.
     *)
     (t = sw.t);

 postcondition:
    (*
     * The student is prompted with the option of saving the changes to the currently
     * opened test before closing it.
     *)
     (tf'.fp.ir) and (tf'.fp.iw) and
     (if (uwts) then
        tf'.t = t
      else
        tf'.t = tf'.t)
   
    and

     (sw'.los = sw.los) and sw.t = nil;

 end CloseTest;

 operation ExitStudentInterface is
    inputs: sw:StudentWorkSpace and tf:TestFile and uwts:UserWantsToSave;
    outputs: tf':TestFile;
    description: (*
        ExitStudentInterface will close the student interface and exit the program. If
        there is a test in the student interface that has been changed but not saved,
        a prompt will appear asking the student if he would like to save the changes
        to the test before exiting the student interface. The operation is disabled if
        a student is taking an in class test.
    *);

 precondition:
    (*
     * The student can exit the application anytime during a session.
     *)
     true;

 postcondition:
    (*
     * If a test is displayed in the student interface that has been changed but not saved,
     * the student is asked if he would like to save the changes to the test before exiting.
     *)
    if(sw.t != nil) then
        (if (uwts) then
            (tf'.fp.iw and tf'.fp.ir and tf'.t = sw.t)
        else
            (tf' = tf))
    else
        (tf' = nil);

 end ExitStudentInterface;

end StudentFile;

(****
 *
 * Module Student Edit defines the operations related to undoing and redoing changes made to a
 * test along with cutting, copying, and pasting text to the test displayed in the student
 * interface. Some object definitions are taken from the Calander RSL specifictations which
 * include the Clipboard and State.
 *)

module StudentEdit;

 from StudentInterface import Text, HighlightedText, StudentWorkSpace, length;
 export Clipboard, PreviousState, PreviousText;

 object Clipboard is
    operations: CutText,CopyText,PasteText;
    components: str:string and l:length;
    description: (*
        Clipboard is the area in the computer's memory where the TextSelection is temporarily
        stored.
    *);
 end Clipboard;

 object State is boolean
    description: (*
        State is a flag indicating if a change has been made to a test displayed in the
        student interface that is not contained in the original test.
    *);
 end State;

 object PreviousState is State
    operations: UndoChange;
    description: (*
        PreviousState is a state of a test before the most recent change.
    *);
 end PreviousState;   

 object PreviousText is Text
    operations: PreviousText;
    description: (*
        PreviousText is the original text before any recent change.
    *);
 end PreviousText;   

 operation UndoChange is
    inputs: txt:PreviousText and ps:PreviousState;
    outputs: txt':Text;
    description: (*
        UndoChange reverts the most recent change made to the currently displayed Test
        in the student interface. The UndoChange operation can only undo changes made to
        the text answer of a question made by a student. The UndoChage operation can be
        used only one time.
    *);
   
 precondition:
    (*
     * Some text must exist in the test and the text must have been changed at least once
     * before the UndoChange operation can be used.
     *)
    (txt'.ps);

 postcondition:
    (*
     * The most recent change to the text on the test is reverted back to its original
     * form before the most recent change was made.
     *)
    (txt' = txt);

 end UndoChange;

 operation CutText is
    inputs: htxt:HighlightedText and cp:Clipboard;
    outputs: ;
    description: (*
        CutText will remove a piece of highlighted text from the test currently displayed
        in student interface. The text will not be deleted, but will be temporarily saved
        on the Clipboard until he decides to put it back onto the test.
    *);
 precondition:
    (*
     * Some text must exist in the test and the student must manually highlight the text to
     * be cut from the test.
     *)
    true;
 
 postcondition:
    (*
     * The highighted text is cut out from the test and saved as a temporary file on the
     * Clipboard.
     *)
    (htxt.l = 0) and (cp.str = htxt.str);
 end CutText;

 operation CopyText is
    inputs: htxt:HighlightedText and cp:Clipboard;
    outputs: cptxt:Text;
    description: (*
        CopyText will copy a piece of highlighted text from the test currently displayed
        in the student interface. The copied text is saved on the Clipboard until the
        student decides to put the copied text back onto the test.
    *);
 
 precondition:
    (*
     * Some text must exist in the test and the student must manually highlight the text to
     * be copied from the test.
     *)
    true;

 postcondition:
    (*
     * The highlighted text is copied from the test and saved as a temporary file on the
     * Clipboard.
     *)
     (cp.str = htxt.str);

 end CopyText;

 operation PasteText is
    inputs: ctxt:Text and cptxt:Text and cb:Clipboard;
    outputs: Text;
    description: (*
        PasteText will put a piece of text that was cut out or copied from the test back
        onto the currently displayed test. The PasteText operation will look for any
        temporarily saved files of text made from cutting or copyig text from the test file
        and put the text saved to the temporary file back onto the test where the cursor is
        currently positioned.
    *);
   
 precondition:
    (*
     * Some temporaray file made from cutting or copying paste must exist.
     *)
    (cb.str != nil);

 postcondition:
    (*
     * The text retrieved from the temporary file made by cutting or copying text from the test
     * is put back on the test in the location where the cursor is currently positioned.
     *)
    true;

 end PasteText;

end StudentEdit;

(****
 *
 * Module StudentTests defines the objects and operations related to taking take home and practice
 * tests along with viewing graded tests inside the student interface. The student should know
 * that only one test may be opened at a time, i.e. if an in class test is opened, no other
 * in class, take home, or practice tests may be opened until the in class test is closed. If
 * a take home test is opened, no other in class, take home, or practice tests may be opened
 * until the take home test is closed. If a practice test is opened, no other in class, take home,
 * or practice tests may be opened until the practice test is closed.
 *
 *)

module StudentTests;

 from StudentInterface import Test, TestFile, FileOpenDialog, LocationAddress, StudentWorkSpace,
                  StudentLogOnScreen;

 object SelectedTest is
    components: Test;
    operations: TakeHomeTest, PracticeTest;
    description: (*
        SelectTest is the menu where a student selects what type of test they need to take.
        TakeHomeTest is the option for tests to be taken out of class and PracticeTest is
        the option for tests to be taken just as practice for the real test. TakeHomeTest and
        PracticeTest are both options of TakeTest, but only one type of test may be taken at a
        time in the student interface.
    *);
 end SelectedTest;

 object TestLocationScreen is
    components: LocationAddress;
    description: (*
        The TestLocationScreen is the interface where a student types in the location of the
        test he needs to take. The location can be an IP Address or a unique network address.
        When a student is done entering the location of the test, the student interface retrieves
        the test from the specified location and displays it in the student interface.
    *);
 end TestLocationScreen;

 object Accessible is boolean
    operations: TakeInClassTest,TakeHomeTest,PracticeTest,CheckGradedTest;
    description: (*
        Accessible is a flag indicating if a LocationAddress is accessible to the student from
        the student interface.
    *);
 end Accessible;

 object OnlyTest is boolean
    operations: TakeInClassTest,TakeHomeTest,PracticeTest;
    description: (*
        OnlyTest is a flag indicating if a test is already open when the student tries to access
        another test. A student may have only one test opened at a time, so OnlyTest is false if
        a student tries to open a test and another test has already been opened by the student
        interface.
    *);
 end OnlyTest;

 operation TakeInClassTest is
    inputs: AdministeredTest:Test and IsAccessible:Accessible and ot:OnlyTest and sw:StudentWorkSpace;
    outputs: sw':StudentWorkSpace;
    description: (*
        TakeInClassTest will retrieve an in class test administered by a teacher from a specific
        computer and display it on the computer monitor for completion and submission. The
        student interface will only retrieve the adminstered test after the LogOn operation
        has confirmed the student's user name and password.
    *);

 precondition:
    (*
     * The administered test must exist and must be accessible to the student from the student interface.
     * The test must also be the only test opened and no other test can be opened until the currently
     * opened test is closed.
     *)
     IsAccessible and ot;

 postcondition:
    (*
     * The administered test is found and is retrieved by the student interface. The student interface
     * displays the test for completion and submission.
     *)
    (sw'.t = AdministeredTest);

 end TakeInClassTest;

 operation TakeHomeTest is
    inputs: tf:TestFile and fod:FileOpenDialog and IsAccessible:Accessible and ot:OnlyTest;
    outputs: t:Test;
    description: (*
        TakeHomeTest will open a test from an accessible directory a student retrieved from
        blackboard or a professor's website. The student downloads the test file and
        opens the file using the TakeHomeTest operation. The operation uses the
        FileOpenDialog interface to open the test file into the student interface. The Save
        and Save as File operations are also enabled. The student can only have one TakeHome
        test opened at a time and must close the currently opened take home test if the
        student wants to open another take home test.
    *);

 precondition:
    (*
     * The test file must exist and be accessible to the student in a directory on his home computer or
     * an individual computer terminal. It must also be downloaded first from a website or other
     * distributor.
     *)
     IsAccessible and ot;

 postcondition:
    (*
     * The test is opened and displayed inside the student interface from the student's home directory.
     *)
    (tf.t = t);

 end TakeHomeTest;

 operation PracticeTest is
    inputs: tf:TestFile and fod:FileOpenDialog and IsAccessible:Accessible and ot:OnlyTest;
    outputs: t:Test;
    description: (*
        PracticeTest will open a test from an accessible directory a student retrieved from
        blackboard or a professor's website. The student downloads the test file and opens
        the file using the PracticeTest operation. The operation uses the FileOpenDialog
        interface to open the test file into the student interface. The Save and Save as
        File operations are also enabled. A practice test cannot be submitted for grading
        once completed.
    *);

 precondition:
    (*
     * The test file must exist and be accessible to the student in a directory on his home computer or
     * an individual computer terminal. It must also be downloaded first from a website or other
     * distributor.
     *)
     IsAccessible and ot;

 postcondition:
    (*
     * The test is opened and displayed inside the student interface from the student's home directory.
     *)
    (tf.t = t);

 end PracticeTest;

 object GradedTestCount is integer
    description: (*
        GradedTestCount is the limit to how many graded tests a student may have opened at any time
        in the student interface.
    *);
 end GradedTestCount;
                                               
 operation CheckGradedTest is
    inputs: LocationAddress and grdt:Test and IsAccessible:Accessible and sw:StudentWorkSpace;
    outputs: sw':StudentWorkSpace;
    description: (*
        CheckGradedTest will retrieve a graded test file at the specified LocationAddress and
        display it in the student interface. If the LocationAddress cannot be found or does not
        exist, a prompt appears stating the specified location could not be found. The
        LocationAddress must also be thirty characters or less and must be a single string. The
        student may also open multiple graded tests up to a maximum of five in the student
        interface.
    *);

 precondition:
    (*
     * The LocationAddress must exist and must be accessible to the student from the
     * student interface. The test must also exist and be accessible to the student when attempting
     * to retrieve the test.
     *)
     IsAccessible and sw.t = nil;

 postcondition:
    (*
     * The graded test is found in the Location at the LocationAddress, retrieved from the
     * LocationAddress, and then displayed in the student interface.
     *)
    (sw'.t = grdt) and sw'.los = sw.los;

 end CheckGradedTest;

end StudentTests;


Prev:
5.3. QuestionBank

Up:
5. Formal Specifications
Next:
5.5. TestAdminister