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
38 changes: 38 additions & 0 deletions TestingLabAnswers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Chris Sheehan
## 2/10/15
## Testing Lab


-



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

One mistake when making an array one can forget to encapsulate it, which can cause to many values to be added, or anything else a user could do to mess it up. A second mistake can be declaring the array as the wrong type value which would prevent it from working at all. A third mistake could be to accidently put a double in an array of integers.



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

With a new instance of a class the scoreboard would be empty, with a value of 0 high scores.

With a single mutation such as adding a score the method `Scoreboard` would have 1 value as opposed to the previous amount of zero values. The method `isHighScore` would return true for the entered score being a highscore seeings as there is only one. The list would be changed through `addScore` where the score and name would be added to the appropiate position on the list because it is a high score, being the only score. The method `getName` would return the name of the one high score. Finally the method `getNumScores` would return the value 1 for the number of high scores.

With multiple mutations the method `Scoreboard` would hold the top 10 high scores, which means after 10 recorded scores not every score added will make it onto the array. The method, `isHighScore` will return true if the value entered is one of the top 10 high scores, otherwise it will return false. `addScore` would add a score and name to the appropiate positon on the list if it is higher then the lowest top score. `getName` would return the name of the specified positon on the scoreboard as usual. `getScore` would return the score based on the position you enter as usual. Finally `getNumScores` would return the number of high scores that are in the scoreboard.



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

A new instance would have the inputed start and stop values. `contains` that would return true if the value you give it is equal to or greater than the first value, and less than the second. `getWidth` would give you the start and stop values. `getMin` would return the smaller of the two values defining the range, would would be the start value, `getMax` would return the larger of the two values which would be the stop value. `Range intersection` would return a new range if the number you input overlaps with your first range and a second range.

There are no mutator methods in this class.

You can find out the largest number, smallest number and the boundaries of the range.

When you pass the range something other than a double.




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

public Average(){
}

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

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

int getCount(){
return count;
}


}
80 changes: 80 additions & 0 deletions src/AverageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 testFiveValues()
{
Average avg = new Average();

avg.addValue(1.0);
avg.addValue(2.0);
avg.addValue(3.0);
avg.addValue(4.0);
avg.addValue(5.0);


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

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

avg.addValue(-2.0);
avg.addValue(-1.0);
avg.addValue(0.0);
avg.addValue(1.0);
avg.addValue(2.0);


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

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

avg.addValue(1.0);
avg.addValue(1.0);
avg.addValue(1.0);
avg.addValue(1.0);
avg.addValue(1.0);


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

}
10 changes: 10 additions & 0 deletions src/AverageTestdrive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class AverageTestdrive{
public static void main(String[] args) {
Average a = new Average();

// a.addValue(0);

System.out.println(a.getAverage());
System.out.println(a.getCount());
}
}
52 changes: 52 additions & 0 deletions src/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
public class Range{
private double start;
private double stop;
private double start1;
private double stop1;

Range(double start, double stop){
if (start == stop) {
this.start = 0.0;
this.stop = 0.0;
}
else {
this.start = Math.min(start, stop);
this.stop = Math.max(start, stop);
}
}

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

double getWidth(){
return Math.abs(start - stop);
}

double getMin(){
return start;
}

double getMax(){
return stop;
}

Range intersection(Range other){

if (start == other.getMin() && stop == other.getMax()) {
return new Range(start, stop);}
else if (stop < other.getMin()) {
return new Range(0.0,0.0);}
else if (other.getMax() < start) {
return new Range(0.0,0.0);}
else{
this.start1 = Math.max(start, other.getMin());
this.stop1 = Math.min(stop, other.getMax());
return new Range(start1, stop1);
}
}

}
49 changes: 49 additions & 0 deletions src/RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 testSeperateRanges() {
Range r = new Range(0.0, 10.0);
Range o = new Range(11.0, 15.0);
Range intersection = r.intersection(o);
assertEquals(10.0, r.getMax());
assertEquals(0.0, intersection.getMin());
assertEquals(0.0, intersection.getMax());
assertEquals(0.0, intersection.getWidth());


}

public void testSameRange() {
Range r = new Range(0.0, 10.0);
Range o = new Range(0.0, 10.0);
Range intersection = r.intersection(o);
assertEquals(0.0, intersection.getMin());
assertEquals(10.0, intersection.getMax());
assertEquals(10.0, intersection.getWidth());


}
public void testOverlappingRange() {
Range r = new Range(0.0, 10.0);
Range o = new Range(3.0, 11.0);
Range intersection = r.intersection(o);
assertEquals(3.0, intersection.getMin());
assertEquals(10.0, intersection.getMax());
assertEquals(7.0, intersection.getWidth());


}

}