Due September 29, 2016
This assignment must be done as a team using GitHub. The goal is to develop a small application using Test Driven Development; you will write JUnit test cases to "specify" the behavior of the implementation and also write Java code for the implementation. Finally you will measure code coverage for your test cases.
Note that we are building your skillset. In P2 you learned to use GitHub. In P3 you will learn to use JUnit while working with GitHub. This will get you ready for the chat project where you will be adding new features, writing test cases, as well as using GitHub.
This description has been adapted from a previous assignment written by Ken Shrum, who used to teach a class at Colorado State University in the past.
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.
World represents an n*m grid of Objects, where the coordinates wrap as described above. Note that these Objects refer to instances of the class java.lang.Object.
Give it a constructor that takes n and m, where n gives the number of locations possible in the West-East direction, and m gives the number of locations possible in the South-North direction.
Give it a second constructor that takes just n, meaning an n*n grid. Use the "this" form to implement it in terms of the first constructor.
Give it a method get(int x, int y) which returns the object at x, y in
the grid, without wrapping. Declare this method protected rather
than public. Don't check x and y for being within range, just index
the underlying array.
This use of protected allows other classes in the same package (like Coordinate)
to call the entry point, but not classes outside of the package.
Similarly, give it a protected method put(int x, int y, Object o) to place
the Object o in the grid. Declare this method protected rather
than public. Don't check x and y for being within range, just index
the underlying array. Do not wrap.
Give it a method get(Coordinate c) which returns the object at c, implemented
in terms of the get() method in the Coordinate class.
Give it a method put(Coordinate c, Object o) which puts the object o at the
x,y position indicated by Coordinate c.
Give it a simple toString method that returns something like "World(n, m)" with the correct values of n and m.
Do not implement equals or hashCode.
Coordinate represents an x,y position in a particular
2D world (where x and y are ints). The x,y in a Coordinate must always
be valid, i.e. in the 0..n-1, 0..m-1 space
Give it a constructor that takes a World, x, and y. This constructor
must handle wrapping
Give it a method get() which returns the object at the specified Coordinate
in the World this Coordinate is using
Give it a method put(Object o), which replaces the Object in the grid with
the Object o provided as the argument.
Give it a method equals(Object other). Two Coordinates are equal
if they represent the same location in exactly the same World object.
You must compare the Worlds for identity using ==
Give it a method hashCode(), which returns the sum of values of x and y and the
hashcode of its
Give it methods north(), south(), east(), and west() that return the adjacent Co
in those particular directions. North is the +y direction, East is
the +x direction, etc. These methods must handle wrapping
give it a method toString() that returns something like
"Coordinate(x,y) in World(n,m)"
Remember that you're doing test-first development. Write
a unit test first, then write the code that will pass it. Iterate
on this. You'll turn in your test code in addition to the
code for World and Coordinate classes.
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. For example, you can use instances of Integer or String.
We have created a Java project containing a package called cs314.p3 that consists of two empty classes (World.java and Coordinate.java). This project has been provided in your team's GitHub repository. You will use Git from the command line to pull the code into your local Eclipse environment.
3.1. Set up Git
- In Eclipse go to Window→Preferences→Team→Git and look at the Default Repository Folder. It's most likely "$HOME/git" unless you changed it.
- In a terminal window, cd <Default repository folder>.
- Go to your repository directory: cd cs314_xx, where xx refers to your team number 01, 02, 03, etc.
- This directory should contain three sub-directories:
- Pull the remote repository:
- git pull
- when prompted, enter your GitHub user name and password.
- Now the directory should also have P3 in it.
3.2. Add Project to Eclipse
The following steps tell you how to add the project to Eclipse.
- Open Eclipse and go to File→Import.
- Choose Git→Projects from Git, then NEXT.
- In the "Select Repository" source window, choose Existing Local Repository.
- In the "Select a Git Repository" window, choose cs314_xx.
- In the "Select a wizard to use for importing projects" window, click the "Import existing Eclipse projects" radio button.
- Select P3.
- In the "Import Projects" window, P3 should be checked. If not, check only P3.
- P3 will be imported as a new project and will be associated with your cs314_xx repository.
3.3. Implement the Code and Test Cases
Once the project is in your Eclipse workspace, you will perform the following tasks.
- Create the following four classes according to the description following the class list. (4X7 = 28 points)
- WorldTest.java: Contains JUnit tests for the class called World.
- World.java: Contains the implementation for the class called World.
- CoordinateTest.java: Contains JUnit tests for the class called Coordinate.
- Coordinate.java: Contains the implementation for the class called Coordinate.
- Create a class called TestAll in the file TestAll.java that defines the test suite containing all the test classes that you have written. (2 points)
3.4. Measure Code Coverage Obtained by Your Test Cases
- Install EclEmma:
- Go to Help -> Install New Software...
- Click on Add...
- Enter location: http://update.eclemma.org/ name : EclEmma Update Site and click ok.
- After clicking it will take some time to EclEmma plugin appear in the text box.
- Click Select All and then Next.
- Click next, accept license agreement and client Finish. Ignore the security warning and restart eclipse.
- Use EclEmma:
- Select project P3.
- At the top where you have the Play buttons for running programs, click on the down-arrow next to the play button that has a red and green rectangle on the bottom-left of the play button.
- You can run the project as JUnit or as Java Application.
- You should be able to view Coverage in the view Console. You can expand the package in the console and view coverage for individual files. If you run multiple times as you add test cases, you can view new coverage by selecting the sessions from a dropdown menu (the one with gears).
- You can also right click on project P3, and select Properties. Click on Coverage to see a summary of various types of coverage.
- The code view will show colors indicating which parts of the code are covered (or not).
- green for fully covered lines
- yellow for partly covered lines
- red for lines that have not been executed at all
Prepare Coverage Report
(5 points) Copy the coverage numbers as part of the report.
To get full points for this part, you must do the following:
- Your implementation code and test code must compile.
- Your tests must pass on your own implementation. If you notice that a test fails, don't remove the test. Instead fix your implementation.
- Your implementation must pass our tests.
- Your tests must find the faults we have seeded in our own implementation.
- You must have written several test cases that use the strategies discussed in class (equivalence classes and boundary values). Your test code should use a variety of JUnit assertions.
- Each test case method should test only one aspect. Do not make your test method too long; that's an indication that a test case is trying to test for multiple aspects.
4. Appropriate Use Of GitHub (5 points)
To get full points for this part:
- GitHub logs for the repository pull review system show the student has requested reviews of their proposed changes to the master. (1 point)
- GitHub logs for the repository pull review system show the student has reviewed their teammates' proposed changes to the master. (1 point)
- No work occurs directly on the master branch and no merge is done to the master branch without using the pull review system first. (3 points)
You will submit the following items for this project via canvas, one submission per team.
- CR.pdf: Coverage report
- P3.jar: Export P3 as a jar file preserving the structure and including only Java source files.