Question: Create a complete set of unit tests for the Cache class. I have created a test class called CacheTests that contains a sample test. You
Create a complete set of unit tests for the Cache class. I have created a test class called CacheTests that contains a sample test. You should add your tests to this class.
The key to testing class implementations is to realize that it is not usually possible to test each constructor and method in isolation. For example, to test the getOwner() method of the Cache class, you must first use the constructor to create a Cache object.
package cs1410;
import static org.junit.Assert.*; import org.junit.Test;
public class CacheTests { /** * An example test for Cache objects */ @Test public void test () { Cache c = new Cache("GCRQWK\tOld Three Tooth\tgeocadet\t3.5\t3\tN40 45.850\tW111 48.045"); assertEquals("GCRQWK", c.getGcCode()); } }
Design a representation and then declare and document your instance variables.
Implement the constructor. Each line of the file caches.txt is an example of a string that the constructor should be able to take as a parameter. (Hint: Use the String split method.)
Implement the methods (other than toString, which is already complete).
Test/debug/modify your Cache and CacheTests classes until you are certain that the Cache class behaves according to its specifications.
package cs1410; /** * Represents a variety of information about a geocache. A geocache has a title, an owner, a difficulty rating, a * terrain rating, a GC code, a latitude, and a longitude. */ public class Cache { // TODO: Put representation here /** * Creates a Cache from a string that consists of these seven cache attributes: the GC code, the title, the owner, * the difficulty rating, the terrain rating, the latitude, and the longitude, in that order, separated by single * TAB ('\t') characters. * * If any of the following problems are present, throws an IllegalArgumentException: *- *
- Fewer than seven attributes
- *
- More than seven attributes
- *
- A GC code that is anything other than "GC" followed by one or more upper-case letters and/or digits
- *
- A difficulty or terrain rating that parses to anything other than the doubles 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, * or 5.
- *
- A title, owner, latitude, or longitude that consists only of white space
- */ public Cache (String attributes) { // TODO: Implement } /** * Converts this cache to a string */ public String toString () { return getTitle() + " by " + getOwner(); } /** * Returns the owner of this cache */ public String getOwner () { // TODO: Implement return ""; } /** * Returns the title of this cache */ public String getTitle () { // TODO: Implement return ""; } /** * Returns the difficulty rating of this cache */ public double getDifficulty () { // TODO: Implement return 1.0; } /** * Returns the terrain rating of this cache */ public double getTerrain () { // TODO: Implement return 1.0; } /** * Returns the GC code of this cache */ public String getGcCode () { // TODO: Implement return ""; } /** * Returns the latitude of this cache */ public String getLatitude () { // TODO: Implement return ""; } /** * Returns the longitude of this cache */ public String getLongitude () { // TODO: Implement return ""; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
