CS314: Assignment A2
Unit testing using the JUnit framework

Assigned: Sep 9, 2014
Due: Sep 18, 2014
50 points

Goals

The goals of this assignment are as follows:

  1. Develop a unit testing plan for testing Java classes that you will implement. The specifications for the Java classes are given to you.
  2. Implement a test driver using the JUnit framework.
  3. Execute the tests using JUnit.


Getting started

Read the notes on Testing and JUnit; Test Infected; and the JUnit Cookbook. These examples are mostly based on JUnit 3.8, which may not work with JUnit 4.11 on our lab machines.

JUnit details can be obtained from www.junit.org. JUnit is already integrated with Eclipse, thereby providing several advantages. Environment variables are set up "automagically". Test execution is tied to the Eclipse debugger, so you can view what went wrong. Test driver skeletons are generated; you just need to fill in the test cases.


Tasks

Certain games use a rectangular grid for the world, and allow the world to "wrap" from top to bottom and from left to right.  Conceptually, this makes a doughnut-shaped world: if you keep going "North" you eventually wrap back around to where you were, and if you keep going "East" you similarly wrap back around.  Note that going North is the +y direction, and going East is the +x direction. We're going to implement a couple of classes to hide the details of the representation from client code.

Any object can be stored in the grid. For testing purposes, feel free to choose something that is simple to compare with the expected object returned by a get method. You can use instances of Integer or String, for example.

Here is an example test case. We will use test cases like this to test your code.
public void testStoreWorld() {
    World world = new World(10, 15);
    Coordinate coordinate = new Coordinate(world, -25, -40);
    Object object = new Object();
    coordinate.put(object);
    assertEquals("Not getting same object of World(10, 15) put using Coordinate(world, -25, -40) and get using world.get(5, 5) ", object, world.get(5, 5));
}

Note that any integer value is possible, including negative values. If there is no object put into a location, you should return null. Make sure you implement the equals method properly since otherwise you may lose a lot of points.


Deliverables and submission

All the classes that you write must be in a package called cs314.a2. The classes are as follows:

Submit a single jar file, called a2.jar, using Assignment Submission in RamCT that contains the above files in the correct directory structure as described in the next paragraph. Click here for a sample jar file that contains the correct structure. Here are some instructions on how to create jar files.

The folder (or directory) hierarchy must be cs314/a2. The Java source files must be present in the cs314/a2 folder of the hierarchy. When you create the jar file, build it from the top of the directory hierarchy. The submitted file must correctly unpack the .java files into a subdirectory cs314/a2. Since the grader will use a script to run your tests it is required you to strickly follow the given file format. The grader will first run your classes with our test cases and then run your testcases with our faulty code. Points will be awarded for test cases that fail due to our faults.

Note:


Grading criteria

Up to 5 points may be deducted for not following the packaging structure or names used for the classes and the methods of each class.