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
10 changes: 10 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Testing Lab
##Andrew Reed

**Question 1:** One mistake that can be made when making an array is trying to fit two or more data types into an array (which has a specific data type) like trying to put a score and a name (string) in the same array. Another forgetting order the scores in the array from greatest to least. A third problem that might arise is, if using parallel rays instead of an object to record the scores and names, then one might forget to order both arrays at the same time, leading to the scores and the names to be out of order, thus the data being incorrect.

**Question 2:** If a new scoreboard were to be created, then it would simply be a scoreboard with no values in it. If a single mutation were to occur to the scoreboard, then the scoreboard would be a scoreboard with one value and one name in it. If multiple mutations were to occur then the scoreboard would have multiple scores (with a maximum of 10 scores) each attached with a corresponding name, and ordered by top score to lowest score.

**Question 3:** A brand new instance of the class would be a range of [0, 0), which would be empty. There is no mutation being done in this class, however the interesting thing that this class can do is create a new range based on where two ranges start and end (where they intersect). All other methods are call methods. The boundary conditions of this lab are any two numbers so long as they aren't equal to each other, if they are they will return an empty range.

**Optional Question:** After running a 1,000,000,000 trial Monte Carlo simulation, I found that the probability of ranges intersecting when all points of the ranges are randomly generated between 0 and 1 is 0.666670703. The average length of these intersections was equal to 0.20001405957047122.
39 changes: 39 additions & 0 deletions src/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public class Average
{
private double sum;
private int count;

public Average()
{
sum = 0.0;
count = 0;
}

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

public double getAverage()
{
double s = 0;

if (sum == 0)
{
s = 0;
}

if (sum != 0)
{
s = sum/count;
}

return s;
}

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

/**
* A JUnit test case class.
* Every method starting with the word "test" will be called when running
* the test with JUnit.
*/
public class AverageTest extends TestCase {

/**
* A test method.
* (Replace "X" with a name describing the test. You may write as
* many "testSomething" methods in this class as you wish, and each
* one will be called when running JUnit over this class.)
*/
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 testDifferentValues()
{
Average avg = new Average();

avg.addValue(5.5);
avg.addValue(6.5);
avg.addValue(7.5);
avg.addValue(8.5);
avg.addValue(9.5);

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

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

avg.addValue(5.5);
avg.addValue(-5.5);
avg.addValue(3.5);
avg.addValue(-1.5);
avg.addValue(-2);

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

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

avg.addValue(5.5);
avg.addValue(5.5);
avg.addValue(5.5);
avg.addValue(5.5);
avg.addValue(5.5);

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

}

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

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

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

if (stop == start)
{
min = 0;
max = 0;
}
}

public boolean contains(double value)
{
boolean s = false;
if (value >= min && value < max)
{
s = true;
}

if (value < min || value >= max)
{
s = false;
}

return s;

}

public double getWidth()
{
return max - min;
}

public double getMin()
{
return min;
}

public double getMax()
{
return max;
}

public Range intersection(Range other)
{
double min2 = other.getMin();
double max2 = other.getMax();

double min3 = 0.0;
double max3 = 0.0;

if (min > min2)
{
min3 = min;
}

if (min2 > min)
{
min3 = min2;
}

if (min2 == min)
{
min3 = min;
}

if (max < max2)
{
max3 = max;
}

if (max2 < max)
{
max3 = max2;
}

if (max2 == max)
{
max3 = max;
}

if (max2 <= min)
{
min3 = 0;
max3 = 0;
}

if (max <= min2)
{
min3 = 0;
max3 = 0;
}

if (min == min2 && max == max2)
{
min3 = 0;
max3 = 0;
}

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

/**
* A JUnit test case class.
* Every method starting with the word "test" will be called when running
* the test with JUnit.
*/
public class RangeTest extends TestCase {

/**
* A test method.
* (Replace "X" with a name describing the test. You may write as
* many "testSomething" methods in this class as you wish, and each
* one will be called when running JUnit over this class.)
*/
public void testZeroRange() {

Range r = new Range(0, 0);

assertEquals(0.0, r.getWidth());
assertEquals(0.0, r.getMin());
assertEquals(0.0, r.getMax());
assertEquals(false, r.contains(0));
}

public void testPositiveRange() {

Range r = new Range(3, 7);

assertEquals(4.0, r.getWidth());
assertEquals(3.0, r.getMin());
assertEquals(7.0, r.getMax());
assertEquals(true, r.contains(3.5));
}

public void testFlipPositiveRange() {

Range r = new Range(3, 7);

assertEquals(4.0, r.getWidth());
assertEquals(3.0, r.getMin());
assertEquals(7.0, r.getMax());
assertEquals(true, r.contains(3.5));

}

public void testNegativeRange() {

Range r = new Range(-4, -1);

assertEquals(3.0, r.getWidth());
assertEquals(-4.0, r.getMin());
assertEquals(-1.0, r.getMax());
assertEquals(true, r.contains(-2.5));

}

public void testFlipNegativeRange() {

Range r = new Range(-1, -4);

assertEquals(3.0, r.getWidth());
assertEquals(-4.0, r.getMin());
assertEquals(-1.0, r.getMax());
assertEquals(true, r.contains(-2.5));
}
//We now know that there isn't anything wrong with getWidth getMin getMax or contains methods.
//If a problem arises in testing of intersection method
//it will be because of a bug in the intersection method and not any other method

public void testIntersectionRange() {

Range r = new Range(3, 7);
Range s = new Range(2, 4);
Range bleh = r.intersection(s);

assertEquals(1.0, bleh.getWidth());
assertEquals(3.0, bleh.getMin());
assertEquals(4.0, bleh.getMax());
assertEquals(true, bleh.contains(3.5));
}

public void testReverseIntersectionRange() {

Range r = new Range(3, 7);
Range s = new Range(2, 4);
Range bleh = s.intersection(r);

assertEquals(1.0, bleh.getWidth());
assertEquals(3.0, bleh.getMin());
assertEquals(4.0, bleh.getMax());
assertEquals(true, bleh.contains(3.5));
}

public void testSameRange() {

Range r = new Range(3, 7);
Range s = new Range(2, 4);
Range bleh = r.intersection(r);

assertEquals(0.0, bleh.getWidth());
assertEquals(0.0, bleh.getMin());
assertEquals(0.0, bleh.getMax());
assertEquals(false, bleh.contains(0.0));
}

public void testNoIntersectionRange() {

Range r = new Range(3, 7);
Range s = new Range(2, 3);
Range bleh = s.intersection(r);

assertEquals(0.0, bleh.getWidth());
assertEquals(0.0, bleh.getMin());
assertEquals(0.0, bleh.getMax());
assertEquals(false, bleh.contains(0.0));
}

public void testReverseNoIntersectionRange() {

Range r = new Range(3, 7);
Range s = new Range(2, 3);
Range bleh = r.intersection(s);

assertEquals(0.0, bleh.getWidth());
assertEquals(0.0, bleh.getMin());
assertEquals(0.0, bleh.getMax());
assertEquals(false, bleh.contains(0.0));
}

public void testOneIsSmallerRange() {

Range r = new Range(-3, 7);
Range s = new Range(2, 3);
Range bleh = r.intersection(s);

assertEquals(1.0, bleh.getWidth());
assertEquals(2.0, bleh.getMin());
assertEquals(3.0, bleh.getMax());
assertEquals(false, bleh.contains(3.0));
}
}

Loading