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
24 changes: 24 additions & 0 deletions Questions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CSCI 121: Computer Science II
## Testing Lab
***Question 1***
Three mistakes that can be made when using an array is forgetting that 0 is apart of the
array, everything in the array has to be the same type, and make sure that all parts of
the array are set to null.

***Question 2***
After one configuration of a Scoreboard for both getScore() and getAverage() in the
instance of a class both methods would be empty, or no values. In an instance with a
single mutation in getScore()there will be one value added, while getAverage() would still
be empty. In an instance with multiple mutations getScore() will have one added value for
the amount of times that the mutation occurs. getAverage() will have a value at this
point.

***Question 3***
What would a brand new instance of the class look like?
It would be empty with no values because they haven't been assigned yet.
What is the simplest mutation possible for the class?
There is no simple mutation possible for this class at this point.
What else can we do to an instance of the class?

What are the boundary conditions for the class?
There are no boundary conditions, currently it is laced at 0 for testing.
30 changes: 30 additions & 0 deletions scr/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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;
}
}




61 changes: 61 additions & 0 deletions scr/AverageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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(1);
avg.addValue(2);
avg.addValue(3);
avg.addValue(4);
avg.addValue(5);

assertEquals(3.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 testFiveValuesAverage() {

Average avg = new Average();

avg.addValue(2);
avg.addValue(2);
avg.addValue(2);
avg.addValue(2);
avg.addValue(2);

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



41 changes: 41 additions & 0 deletions scr/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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);
}
}


22 changes: 22 additions & 0 deletions scr/RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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);
}

}