Using the Algorithm-Test Environment and Submitting Assignments


Mac vs Windows

Since you've had the pre-requisites, we will assume you know how to compile and execute Java programs at the command-line.

If this is not the case, you will need to do that IMMEDIATELY because nothing will work in the class without that. Generally, the steps involved are:

 

Editing and compiling:

 

Getting your directory structure set up:



The Test Environment:

In this course, you will use two tools developed for testing and submitting programs.

The Algorithm Test Environment is a Java-based testing environment for algorithms:



Download the test environment and run the demo:
  1. Create a new directory called cs3212 under your home directory.

  2. Download algtest.jar in the cs3212 directory. (Newer version: 9/12/2023: algtest.jar compiled with JDK 20.0.1)

  3. You will create subdirectories off of cs3212 for various assignments and exercises.

  4. Set up your initialization, CLASSPATH etc based on your laptop: Mac/Linux users: how do you know which shell is being used? Type echo $SHELL in your Terminal.

  5. Note about installing Java: If you install a new version of Java, you will likely need to edit your PATH environment variable, so that the path to the Java executables (java, javac, jar etc) is in the PATH.
    • Linux/OS-X: This means doing for PATH something similar to what you did for CLASSPATH above. For example, on old OS-X laptop might have had Java-7 pre-installed. If you want to replace that with a new version (Version 10 in the example below), you'd need to add something like
      
      export PATH=/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home/bin:$PATH
           
      to your .profile or .bash_profile
    • Windows: You would need to find the path to the Java executables (javac etc) and add the full path to your PATH environment variable. Then, bring up a command-prompt and test that you are able to run the compiler.
    • Note: Some tools in Java come pre-installed with Windows, but not all. You may need to install the latest JDK and add the /bin folder within that JDK to your PATH variable.

  6. Download min.jar into the cs3212 directory to unpack it at the command line:
    
           jar xvf min.jar
         
    (Alternatively, download min.zip and unpack that.)

  7. This will create a directory called min.

  8. Go to the cs3212/min directory and run the demo:
    
         java -jar ../algtest.jar alg.props
         
    You have just executed a test program, Min.java, in the Algorithm-Test environment. Here's an explanation:
    • The test-environment first does some correctness testing, the results of which are that some tests are "passed". If an algorithm fails a test, an appropriate message is displayed.
    • Next, the second phase is performance testing, which plots a graph.
    Now examine the source files:
    • Open the file Min.java.
    • Min.java is a really simple (demo) program: it scans an array to find the least element.
    • The import statements are necessary to be able to use the edu.gwu.algtest package.
      Important: you will need these import statements (but not package statements) for your code.
    • Check that your classpath is correct by compiling Min.java.
    • Now, note that the class Min implements the MinAlgorithm interface as well as the Algorithm interface (which MinAlgorithm extends). The methods getName() and setPropertyExtractor() methods are from the Algorithm interface.


Java interfaces and props files

When you write code for assignments in this course, you will often be asked to have your Java class implement an interface. For example, in just about every exercise/assignent, your classes will implement the Algorithm interface.

  • Important: Do NOT write the code for these interfaces. These interfaces are already inside algtest.jar.
  • Instead, your class implements an interface by including methods that are specified in the interface.
  • This, in fact, is how algtest.jar can call your code.
  • Examine the file Min.java example above and you will see that it implements both the MinAlgorithm interface and the Algorithm interface:
    
    import edu.gwu.algtest.*;                   // These three import's are needed.
    import edu.gwu.debug.*;
    import edu.gwu.util.*;                
    
    public class Min implements MinAlgorithm {  // MinAlgorithm is the interface
    
        // ...
    
    }
         
  • What does this mean? It means Min.java has to have methods that are specified in those interfaces.
  • Not all these methods need to have code in them, but the methods need to be there.
  • You noticed that the class Min above implemented only MinAlgorithm interface. Why then did we say that it also implements the Algorithm interface? Because if you look at the MinAlgorithm interface you will see that it extends Algorithm, which means that it inherits all the methods in Algorithm.

The other thing to keep in mind are the props files, with names like min.props and ex1.props (for Exercise 1, for example).

  • These are "set up" files that direct the algtest test-environment.
  • They tell the test environment the name of your files, what to test, whether to run simple tests (to test correctness) or whether to run a test with large data (for performance comparisons between algorithms).


Submission

All submissions are to be done in Blackboard and in each case you will upload a zip file in the appropriate place.

Here are some details, using the first exercise as an example:

  • Create (just once) a directory called cs3212 for all your work in this course.
  • Under this, create a directory called ex1.
  • In this directory, you will have all your code for Exercise 1, AND a single PDF with your written homework.
  • For Exercise 1, your PDF will be called ex1.pdf, for Assignment 1, it will be called assignment1.pdf, and so on.
  • Make a zip of this directory and call it ex1.zip.
  • Upload ex1.zip into Blackboard under Exercise-1.

Here are some details for submitting the module exercises for Module 1 (as an example:

  • Under the cs3212 directory, create a directory called module1.
  • Write all your module1 code in this directory.
  • Also, include a single PDF called module1.pdf which will have answers to non-coding questions.
  • When it's time to submit, make a zip of this module, calling it module1.zip and upload that into Blackboard.

Written (pen-and-paper) homework

An important goal in this course is to develop the skill of algorithmic thinking, a good deal of which can be practiced without writing any code. Thus, some of the work in this course is "pen and paper":

  • We use the term pen-and-paper metaphorically. You will actually submit a PDF document.
  • There are many ways to make this PDF document:
    • Actually write on paper (neatly!) and then scan into PDF.
    • Learn how to use Latex, the gold standard for math and CS. This is a bit painful the first time, but there are now many free tools (and Latex itself is free) that make it easier.
    • Use some other word processor.