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
31 changes: 31 additions & 0 deletions AnswersTestingLab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
**Question 1:** Arrays start at zero, if you forget this your counting will be off.
Forgetting to initialize objects in arrays. An array in java is really an object reference,
creating an array with new will result in an empty reference. It is also important to keep
in mind that all elements in an array are set to null. In order to have a complete array,
each element must be linked to a real object reference. In java, an array can not be of
mixed types. When looping over arrays you have to be careful to remember to set the
condition when i is less than length.

**Question 2:**
For a new instance of the class, it will look empty meaning there is no values in the two
arrays. It will have the arrays but we haven't put anything in them yet.

For an instance of a single mutation, it will have added one item to the start of the
score and string array, everything else will be blank.

For an instance with multiple mutations, will depend on scores, will be in sorted order.

**Question 3:**
What would a brand new instance of class look like?
It would be empty because we haven't assigned values yet.

What is the simplest mutation possible for the class?
There is actually nothing that can be mutated.

What else can we do to an instance of the class?



What are the boundary conditions for the class?
Boundary conditions are what is right on the edge of being correct. This is most likely
to be where mistakes happens. Currently it is at 0 for testing.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/._.DS_Store
Binary file not shown.
Binary file added src/._AverageTest.java
Binary file not shown.
27 changes: 27 additions & 0 deletions src/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Average {
double sum = 0.0;
int count = 0;

public Average() {
}

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

}

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

public int getCount(){
return count;

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

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

assertEquals(0, avg.getCount());
assertEquals(0.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);
avg.addValue(4);
avg.addValue(6);
avg.addValue(8);
avg.addValue(10);

assertEquals(6.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testFiveValuesZeroAverage(){
Average avg = new Average();

avg.addValue(0);
avg.addValue(0);
avg.addValue(0);
avg.addValue(0);
avg.addValue(0);

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

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

avg.addValue(4);
avg.addValue(4);
avg.addValue(4);
avg.addValue(4);
avg.addValue(4);

assertEquals(4.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
}
44 changes: 44 additions & 0 deletions src/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
public class Range {
private double min;
private double max;

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

if (stop > start) {
max = stop;
}
else {
max = start;
}
}

public boolean contains (double value){
return true;
}

public double getWidth(){
return 0.0;
}

public double getMin(){
return min;

}


public double getMax(){
return max;
}

public Range intersection(Range other){
return new Range(0.0, 0.0);
}


}
24 changes: 24 additions & 0 deletions src/RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 (1.0, 10.0);
assertEquals(10.0, r1.getMax(), 0.001);
Range r2 = new Range(5.0,-1.0);
assertEquals(5.0, r2.getMax(), 0.001);
}


}