Programming with
Data Structures and Algorithms

We expect you to use a testing library that provides the check-expect behavior you saw in Racket. In lecture, we showed how to use check-expect in Java, but additional documentation may be useful for future reference. Instructions for using the testing library in each environment follow:

DrJava Users

Initial Setup

  1. Download the tester library to some central location on your computer (such as a folder for all of your 2102 work).
  2. Download to the same directory.
  3. Start DrJava. Go to the Edit menu, then the Preferences option. Look for the "Extra Classpath" part of the preferences screen. Click "Add", then enter/select the location of tester.jar. Then click "OK".

For each assignment or separate project

  1. Make a new folder to hold all the assignment/project files.
  2. Copy into the new folder.
  3. Put all files for your assignment into the folder. When you want to compile/run your code, make sure that appears as one of the open files in the leftmost panel (open it from the file menu if necessary). Highlight in that panel before you hit run, or you will get an error message saying

    Static Error: This class does not have a static void main method accepting String[]

Experienced Eclipse Users

  1. Download the tester library.
  2. import tester.Tester into your Examples class
  3. In your Run Configurations, set tester.Main as your Main class

Eclipse Newbies

Initial setup

  1. In the directory where you choose to keep your Java files, create two new folders called EclipseWorkspace and EclipseJars.

  2. Download the tester library and save it to your EclipseJars folder.

For each assignment or separate project

Step 1: set up an Eclipse project

  1. Start Eclipse. If Eclipse prompts you for a workspace, browse to the EclipseWorkspace folder you created. If Eclipse doesn't prompt you for a workspace, then in the File menu, choose Switch workspace and browse to your EclipseWorkspace folder.

  2. Create a project: in the File menu select New then Java Project. Where it asks for Project Name type Project1 (you may select a different name, but we will refer to it as Project1 from now on). Make sure that "Use an execution environment JRE" and "Create separate folders for sources and class files" are selected, then select Next.

  3. In the Java Settings pane select the Libraries tab. On the right click on Add External JARs... You will get a chooser window. Navigate to your EclipseJars folder and select the tester jar file you downloaded. Hit Finish.

Step 2: Creating files

  1. In Eclipse, it is customary to keep each class definition and each interface in its own separate file. The convention is to name the file, where Classname is the name of the class or interface that you're defining. In the File menu, choose New and then select either Class or Interface. Once you fill in the filename and click Finish, a pane will open with your class/interface name.

Step 3: Set up the run configuration and run the program

  1. Highlight Project1 in the Package Explorer pane. In the Run menu select Run Configurations.... In the top left corner of the inner pane click on the leftmost item. When you mouse over it should show "New launch configuration". (If this item isn't available, choose Java Application. The New launch configuration item should now be visible.) Select the name for this configuration - usually the same as the name of your project. Where it says Main class: click on Search.... and choose Main - tester. Click Apply and then Run to run your program.

    If you did everything correctly, you should see a message in the Console window that says something about "Tests for the class: Examples". The next time you want to run the same project, hit the green circle with the white triangle on the top left side of the main menu.