Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Answers to Testing Lab

###Carly Thorpe
#### 2/10/15


**Question 1:** Three mistakes you can make when using an array are misinterpreting what the position is in an array (Ex: If the array is histogram[4], you could make the mistake of thinking it is in index 4), you can use doubles and ints at the wrong time, or forget to keep them consistent, and passing a parameter of the wrong type to a method.

**Question 2:** For a new instance of a class, one configuration of a `Scoreboard` would include both `getScore()` and `getAverage()` methods. This `Scoreboard` would be empty. `getScore()` would return nothing because there are no positions that have a score yet and `getAverage()` would be 0.0 because there are no scores added to the scoreboard as soon as a new instance is created. In an instance with a single mutation, `Scoreboard` would have `getScore()` with a parameter passed and would return the score that is in that specific position. It would only have one postition because it was only mutated once. `getAverage()` would return whatever that score in that postition is because it is the sum/num of mutations and there is only one mutation to the method. In an instance with multiple mutations, `Scoreboard` would have multiple scores and when `getScore()` is called with a parameter, it would return the score in that postition. `getAverage()` would change depending on how many mutations are made to the instance.

**Question 3:** Testing Questions for `Range`

1. A brand new instance of the `Range` class would be empty. There are no values added to the class so there would be no methods.
2. There would be no way to simply mutate the instance. All of the methods in the class `Range` are query methods, so you can only ask questions of them. The range is established in the constructor and it can't change unless you create a new instance. You can only test the intersection method. This is because you can change the range that you are comparing the established range to and get different range answers depending on the "other" range you compare it to.
3. The only other thing you can do to the instance of the class is call the other methods and have them return a value. The rest of the methods are query methods so you can only ask questions of them. There's no more mutator methods to change the instance.
4. The boundary conditions of the class are that the range is inclusive at the lower starting value and exclusive at the upper value. Where in the `Average` class, the boundaries depended on if count was equal to zero or not. If count was 0, it returned 0. But if count was >0, it would divide sum by count.


23 changes: 23 additions & 0 deletions src/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Average {
double sum = 0;
int count = 0;

public Average() {
}

public void addValue(double value) {
sum += value;
count += 1;
}

public double getAverage() {
if (count == 0)
return 0;
else
return (double)sum/count;
}

public int getCount() {
return count;
}
}
23 changes: 23 additions & 0 deletions src/AverageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import junit.framework.TestCase;

public class AverageTest extends TestCase {
public void testNewAverage() {
Average avg = new Average();

assertEquals(0, avg.getCount());
assertEquals(0, avg.getAverage(), 0.001);
}

public void testSingleValue() {
Average avg = new Average();

avg.addValue(10.0);
avg.addValue(10.0);
avg.addValue(10.0);
avg.addValue(10.0);
avg.addValue(10.0);

assertEquals(10.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
}
103 changes: 103 additions & 0 deletions src/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
public class Range {
private double start;
private double stop;
private double start2;
private double stop2;

public Range(double min, double max) {
start = min;
stop = max;
}


public boolean contains(double value) {
System.out.println(start);
System.out.println(stop);
System.out.println(value);

if (value >= start && value < stop) {
return true;
}
else{
return false;
}
}

public double getWidth() {
return Math.abs(start - stop);
}

public double getMin() {
return start;
}

public double getMax() {
return stop;

}

public Range intersection(Range other) {
start2 = other.getMin();
stop2 = other.getMax();

if (start == start2 && stop == stop2) {
Range s = new Range(start, stop);
return s;
}

else if (start == start2 && stop > stop2) {
Range s = new Range(start, stop2);
return s;
}

else if (start == start2 && stop < stop2) {
Range s = new Range(start, stop);
return s;
}

else if (stop == stop2 && start < start2) {
Range s = new Range(start2, stop);
return s;
}

else if (stop == stop2 && start > start2) {
Range s = new Range(start, stop);
return s;
}

else if (start < start2 && stop < stop2) {
Range s = new Range(start2, stop);
return s;
}

else if (start > start2 && stop > stop2) {
Range s = new Range(start, stop2);
return s;
}

else if (start > start2 && stop < stop2) {
Range s = new Range(start, stop);
return s;
}

else if (start < start2 && stop > stop2) {
Range s = new Range(start2, stop2);
return s;
}

else if (stop < start2 || stop2 < start) {
Range s = new Range(0,0);
return s;
}

else {
Range s = new Range(0,0);
return s;
}
}
}





104 changes: 104 additions & 0 deletions src/RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import junit.framework.TestCase;

public class RangeTest extends TestCase {
public void testNewRange() {
Range r = new Range(0,2);

assertEquals(true, r.contains(1));
assertEquals(2.0, r.getWidth());
assertEquals(0.0, r.getMin());
assertEquals(2.0, r.getMax());

}

public void testIntersectionEqual() {
Range r = new Range(1.0,3.0);
Range t = new Range(1.0,3.0);

Range intersect = r.intersection(t);
assertEquals(1.0, intersect.getMin());
assertEquals(3.0, intersect.getMax());
}

public void testIntersectionSameStartDifferentEnd() {
Range r = new Range(1.0,5.0);
Range t = new Range(1.0,4.0);

Range intersect = r.intersection(t);
assertEquals(1.0, intersect.getMin());
assertEquals(4.0, intersect.getMax());
}

public void testIntersectionSameStartDifferentStop2() {
Range r = new Range(1.0,4.0);
Range t = new Range(1.0,5.0);

Range intersect = r.intersection(t);
assertEquals(1.0, intersect.getMin());
assertEquals(4.0, intersect.getMax());
}

public void testIntersectionSameStopDifferentStart() {
Range r = new Range(1.0,5.0);
Range t = new Range(2.0,5.0);

Range intersect = r.intersection(t);
assertEquals(2.0, intersect.getMin());
assertEquals(5.0, intersect.getMax());
}

public void testIntersectionSAmeStopDifferentStart2() {
Range r = new Range(2.0,5.0);
Range t = new Range(1.0,5.0);

Range intersect = r.intersection(t);
assertEquals(2.0, intersect.getMin());
assertEquals(5.0, intersect.getMax());
}

public void testIntersectionStartLessStopLess() {
Range r = new Range(1.0,5.0);
Range t = new Range(2.0,6.0);

Range intersect = r.intersection(t);
assertEquals(2.0, intersect.getMin());
assertEquals(5.0, intersect.getMax());
}

public void testIntersectionStartGreaterStopGreater() {
Range r = new Range(2.0, 6.0);
Range t = new Range(1.0, 5.0);

Range intersect = r.intersection(t);
assertEquals(2.0, intersect.getMin());
assertEquals(5.0, intersect.getMax());
}

public void testIntersectionRangeInRange2() {
Range r = new Range(2.0, 5.0);
Range t = new Range(1.0, 6.0);

Range intersect = r.intersection(t);
assertEquals(2.0, intersect.getMin());
assertEquals(5.0, intersect.getMax());
}

public void testIntersectionRange2InRange1() {
Range r = new Range(2.0, 6.0);
Range t = new Range(3.0, 5.0);

Range intersect = r.intersection(t);
assertEquals(3.0, intersect.getMin());
assertEquals(5.0, intersect.getMax());
}

public void testIntersectionDNE() {
Range r = new Range(2.0, 5.0);
Range t = new Range(7.0, 9.0);

Range intersect = r.intersection(t);
assertEquals(0.0, intersect.getMin());
assertEquals(0.0, intersect.getMax());

}
}