Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing-Lab done John Ferguson! #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
20 changes: 20 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# John Ferguson
# Testing Lab 2/12/15

>**Question 1:** List three mistakes we can make when using an array.

**Answer 1:** Three ways we can makes mistakes when using an array is people use length in arrays, arrays already know their length. The a second common mistake is that the array always starts at 0 not 1. A third thing people mistake is storing a type that isn't compatible with the array type, it has to be the same type in the array.

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

**Answer 2:** For a new instance of the class, a configuration could be Class.newInstance(). The arrays are empty in the new class. An instance with a single mutation would increment the array by 1 at the begging of the score array and string array. An instance with multiple mutations depends what the scores are but there will be multiple scores in sorted order in the score array and the string array.

>**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 for the range would look like a new range in the array set at 0 to the range we want.

What is the simplest mutation possible for the class? The simplest mutation for the class would be to increment the range by 1.

What else can we do to an instance of the class? Something else we can do to the instance of the class could be to get the Min and the Max.

What are teh boundary conditions for the class? The boundary conditions for the class are also the min and max because they determine the starting the stopping points.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CSCI 121: Computer Science II
ls# CSCI 121: Computer Science II
## Testing Lab

### Overview
Expand Down
24 changes: 24 additions & 0 deletions src/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Average {
private double sum = 0.0;
private int count = 0;


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

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(1.5);
avg.addValue(10.0);
avg.addValue(5.0);
avg.addValue(3.5);

assertEquals(4.4, 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(9.0);
avg.addValue(9.0);
avg.addValue(9.0);
avg.addValue(9.0);
avg.addValue(9.0);

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


public Range(double start, double stop) {
int randI = (int)(Math.random()*1);
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.0;
double newMax = 0.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);


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

Range r2 = new Range(5.0, -1.0);

assertEquals(-1.0, r2.getMin());
}

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

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

}

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

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

}
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(7.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);
}
}