Using the Algorithm-Test Environment and Submitting Assignments
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:
- The idea is, you will write algorithms and
let the environment do some testing for you.
- There are two kinds of
testing: correctness testing and performance
testing. (There is a third kind available, which we will not describe here).
- In correctness testing, a special test program will feed your
algorithm with different kinds of inputs to see if it "does the right
thing".
For example, a sorting algorithm will be expect to, of course,
sort the input data.
- In performance testing, large data sets will be provided to
examine the run-time performance: how long does your algorithm take
to run (in seconds) on the data sets. A graph is plotted and
displayed for various data sizes.
- You can test several algorithms at the same time, and compare
their run-time performance graphically.
- The environment parameters are controlled by a "properties"
file. If you know what you are doing, you can change the properties
to adjust the parameters of testing (correctness or performance).
The properties include the location (pathname) of your algorithm
(how else will the environment know where to find it?), test
parameters, performance parameters etc.
- How does environment know which method to call in your
algorithm class file? You'll implement an interface known to the
test environment for every algorithm tested.
- Important: It is useful to be able to run just
the correctness tests by themselves (after all, you first want
to get your program working). You can run only the correctness tests
by setting testPerformance=false in the properties file.
This is useful for two reasons: (1) initially you want to complete
correctness testing before performance tests;
(2) the default performance tests expect to display a GUI (which you
can't do on hobbes.
Note: you can set display=false in the properties file
to turn off the display.
Also: you can get a Java display to work on any Unix
workstation in Tompkins 411.
- Important: Do NOT call System.exit
in your code. System.exit causes
execution to halt instantly, without returning to the test environment.
Download the test environment and run the demo:
- Create a new directory called cs151 under your root directory.
- Download this jar file
(or, if you prefer: a gzipped-tar
version)
in the
cs151 directory.
- You will create subdirectories off of cs151 for various
assignments and exercises.
- Set the class-path so that Java can access the
algtest.jar file:
- UNIX: Add this line in your .profile file in your
root directory, substituting your username in the second path.
export CLASSPATH=$CLASSPATH:/home/student/yourusername/cs151/algtest.jar:.
Note: you might need to use:
export CLASSPATH=$CLASSPATH:/home/ugrad/yourusername/cs151/algtest.jar:.
if that's the path to your home directory.
Don't forget the period at the end. Log out immediately and log
back in for the change to take effect.
Note: you will access a jar file in my submit
directory.
- Windows:
set CLASSPATH=%CLASSPATH%;pathtocs151;.
where pathtocs151 corresponds to the path to your cs151
directory, for example, C:\myclasses\cs151.
- Download this jar file
(or a gzipped-tar
version)
into the cs151
directory to unpack it:
% jar xvf min.jar
- This will create a directory called min.
- Go to the cs151/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.
Submission
We have also developed an "assignment submission" tool to help with
encrypting and submitting jar files. Essentially, you will write your
stuff in a directory, jar the directory, copy the jar file to your
submit directory and run our tool on the jar file.
Note: all submissions are to be done on hobbes.
Here are the details, using the first exercise as an example.
Substitute your actual Unix username in place of username below.
- For the first exercise, create a directory under your
cs151 directory called username1.
Example: if your username is beavis, your directory will be named
beavis1.
- Select an 8-digit encrypting key using ONLY alphabets and digits,
for example qfgk9816. Email
this to the TA (all TA's, if there are more than one) and DO NOT
share this key with anyone.
- Now, let's assume you've written your code for the first exercise
(in cs151/username1.
Go to your cs151 directory and type the following command:
% jar cvf username1.jar username1
This "jars" your username1 directory into a single jar file.
You should see a username1.jar file in your cs151 directory.
- Next, encrypt:
% java -jar ~simha/submit/submit.jar -e qfgk9816 beavis1.jar beavis1.jar.crypt
Of course, you should use your crypt key above.
Here, the -e option specifies encryption (as
opposed to decryption with the -d option).
- Place the encrypted version in a subdirectory called /submit
(a subdirectory off of your home directory).
% cp beavis1.jar.crypt ~/submit/.
- Make the crypt file accessible:
% cd
% chmod a+rx submit
% cd submit
% chmod a+r beavis1.jar.crypt
At this point, the TA will be able to copy over your
encrypted file, decrypt it, and un-jar it to test your code.
Anyone else can copy over your crypt file, but should not be able to decrypt it.
- Important: You should follow the instructions closely -
your encrypted jar file will be copied, decrypted, compiled and tested
automatically by a new grading tool we've developed. This tool will
crash on your assignment if not properly submitted.
- Important: Use the same key for future submissions.
Do NOT make other directories/files accessible. (Points may be taken off if this
occurs).
- If specified, submit a
printout (hardcopy) of your code before the due date either in my mailbox, in
class, or slip it under my door.
- In your submissions, please include only your Java source files
(not class files, since we will compile).
You may include other files only if directed to
do so in an assignment/exercise.