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
17 changes: 17 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CSC1 121 Hailey Kester 2/12/15
##Testing lab

**Question1:** List three mistakes we can make when using an array.

**Answer1:** Three mistakes that can be made using using an array would be that you can forget to use an index in order to store the values into an array, forgetting that an array always starts at 0 instead of 1, and lastly you /home/kester/cs121/Testing-Lab/Answers.mdcan try to store a type that is not compatible with the array type; which will not working because the types need to be consistant.

**Question 2:** List at least one configuration of a `Scoreboard` for each of the above scenarios.

**Answer 2:** One configuration of a `Scoreboard` for each of the above scenarios would be for a new instance of the class, there would be an empty array because there is no values inputed yet. With an instance with a single mutation, the configuration would be one item added to beginning of score array and adding array. For an instance with multiple mutations, there would be a mutliple of scores in the array and they would be in array order.

**Question 3:** Answer the "Testing Questions" descripted in the previous section.

**Answer 3:** What would a brand new instance of the class look like? A brand new instance of the class would look like a new `range` set to 0, which would set a new `range` array.
What is the simplest mutation possible for the class? The `range` class does not have any mutators so there is no simplest mutation possible for the class.
What else can we do to an instance of the class? For the range class we can compute the min and max of the range and check to see if they are the starting and stopping point, we can also check the width of the range to see the difference between the min and the max.
What are the boundary conditions for the class? The boundary conditions for the class would be the `getMin` and `getMax` because they determine our starting and stoping point of the range.
30 changes: 30 additions & 0 deletions src/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Average {
private double sum = 0.0;
private int count = 0;

public Average() {

}

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


}

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


return sum/count;
}

public int getCount() {

return count;
}
}

62 changes: 62 additions & 0 deletions src/AverageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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(5.5);

assertEquals(5.5, avg.getAverage(), 0.001);
assertEquals(1, avg.getCount());
}

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

avg.addValue(2.0);
avg.addValue(4.5);
avg.addValue(6.0);
avg.addValue(8.5);
avg.addValue(10.0);

assertEquals(6.2, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());

}

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

avg.addValue(0.0);
avg.addValue(0.0);
avg.addValue(0.0);
avg.addValue(0.0);
avg.addValue(0.0);

assertEquals(0.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());

}

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

avg.addValue(2.2);
avg.addValue(2.2);
avg.addValue(2.2);
avg.addValue(2.2);
avg.addValue(2.2);

assertEquals(2.2, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());

}


}
64 changes: 64 additions & 0 deletions src/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
public class Range {
private double start;
private double stop;

public Range(double start, double stop) {
if (start <= stop) {
this.start = start;
this.stop = stop;
}
else {
this.start = stop;
this.stop = start;
}



}

public boolean contains(double value) {
if ((value >= start) && (value < stop)) {
return true;
}
return false;


}

public double getWidth() {
return stop-start;

}

public double getMin() {
return start;

}

public double getMax() {
return stop;
}

public Range intersection(Range other) {
double newMin = 0;
double newMax = 0;
if (other.contains(start)) {
newMin = start;
}

if (other.contains(stop)) {
newMax = stop;
}

if (contains(other.getMin())) {
newMin = other.getMin();
}

if (contains(other.getMax())) {
newMax = other.getMax();
}


return new Range(newMin, newMax);
}
}
58 changes: 58 additions & 0 deletions src/RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import junit.framework.TestCase;

public class RangeTest extends TestCase {
public void testNewRange() {
Range rng = new Range(0.0, 0.0);
}

public void testMin() {
Range r1 = new Range(1.0, 10.0);
assertEquals(1.0, r1.getMin(), 0.001);

Range r2 = new Range(5.0 ,-1.0);
assertEquals(-1.0, r2.getMin(), 0.001);

}

public void testMax() {
Range r1 = new Range(10.0, 1.0);
assertEquals(10.0, r1.getMax(), 0.001);

Range r2 = new Range(-1.0, 5.0);
assertEquals(5.0, r2.getMax(), 0.001);

}

public void testWidth() {
Range r1 = new Range(10.0, 1.0);
assertEquals(9.0, r1.getWidth(), 0.001);

Range r2 = new Range(5.0, -1.0);
assertEquals(6.0, r2.getWidth(), 0.001);

}

public void testBooleanContains() {
Range r1 = new Range(10.0, 1.0);
assertTrue(r1.contains(4.0));

Range r2 = new Range(5.0, -1.0);
assertFalse(r2.contains(10.0));

assertFalse(r1.contains(10.0));


}

public void testRangeIntersection() {
Range r1 = new Range(10.0, 1.0);
Range r2 = new Range(5.0, -1.0);
Range r3 = r1.intersection(r2);

assertEquals(4.0, r3.getWidth(), 0.001);
}




}