Skip to content

Submission for the Testing Lab #15

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

Open
wants to merge 1 commit 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
22 changes: 22 additions & 0 deletions Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Testing Lab Answers
### John Vonelli

** Question 1 **: Three mistakes that we can make when using an array are as follows. When determining the type of the class, if you would want to have values inserted as a *double* and you would accidentally initialize the array as an *integer*, that would truncate your information so it would fit into the *integer*. Another mistake that one could make when using an array is that you could mistakenly add information to the wrong variable in the array. For example, if you were to have values that was supposed to be added to `array[0]`, but accidentally added to `array[1]`, you could distort your variables and information within your array. Lastly, it is possible that you could use `{}` instead of `[]` when initializing the array, causing a syntax error.

**Question 2**: When making a new `Scoreboard()`, there are no variables and would have no new information besides zero values. When there is a new instance of `Scoreboard()` with one mutation, that would signify that there would be one value within that instance of the class. So the user would be able to utilize the `isHighScore()`, the `getName()`, the `getScore()`, and the `getNumScores()` methods to recieve information. When there is a new instance of `Scoreboard()` with multiple mutations, that would mean that the instance of the class would hold multiple values and information. The user then would be able to utilze the methods mentioned above to access and to understand that information.

**Question 3**: Here are the answers to the testing questions for the `Range` class.

- **1**. A brand new instance of the class would have zero values for the variables, and the class would be ready to be utilized.
- **2**. Besides initializing the constructor `Range()` (which you could initialize to `Range(0,2)`), there are no other mutators that I could manipulate in this class. Thus, there are no other simplier mutations possible for this class.
- **3**. We can check the other methods to find out other information for the instance of the class.
- **4**. The boundary conditions for the `Range()` constructor are as follows. The lower boundary (start) of `Range()` is inclusive, while the upper boundary (stop) of `Range()` is exclusive. So for example, if you initialize `Range(0,2)`, then the range will be valid for 0 through 1.









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

public Average(){
}

public void addValue(double value){
sum += value;
count++;
}
public double getAverage(){
if(count == 0){
return 0;
}
return (double)sum / count;
}
public int getCount(){
return count;
}
}




Binary file added AverageTest.class
Binary file not shown.
53 changes: 53 additions & 0 deletions AverageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 testNotZero(){
Average avg = new Average();
avg.addValue(5.0);
avg.addValue(5.0);
avg.addValue(5.0);
avg.addValue(5.0);
avg.addValue(5.0);
assertEquals(5.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testIsZero(){
Average avg = new Average();
avg.addValue(2.0);
avg.addValue(-2.0);
avg.addValue(1.0);
avg.addValue(-1.0);
avg.addValue(0.0);
assertEquals(0.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testSameVal(){
Average avg = new Average();
avg.addValue(1.1);
avg.addValue(1.1);
avg.addValue(1.1);
avg.addValue(1.1);
avg.addValue(1.1);
assertEquals(1.1, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}



}
Binary file added Range.class
Binary file not shown.
92 changes: 92 additions & 0 deletions Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
public class Range{
private double begin = 0.0;
private double end = 0.0;
private double begin2 = 0.0;
private double end2;
private double width = 0.0;
private double result = 0.0;

public Range(double start, double stop){
begin = start;
end = stop;
}
public boolean contains(double value){
if(value >= begin && value < end){
return true;
}
else{
return false;
}
}
public double getWidth(){
return Math.abs(begin - end);
}
public double getMin(){
return begin;
}
public double getMax(){
return end;
}
public Range intersection(Range other){
begin2 = other.getMin();
end2 = other.getMax();

if(begin == begin2 && end == end2){
Range g = new Range(begin2, end2);
return g;
}
else if(begin2 > begin && end2 < end){
Range g = new Range(begin2, end2);
return g;
}
else if(begin2 < begin && end2 > end){
Range g = new Range(begin, end);
return g;
}
else if(begin2 == begin && end2 > end){
return new Range(begin2, end);
}
else if(begin2 == begin && end2 < end){
Range g = new Range(begin2, end2);
return g;
}
else if(begin2 < begin && end2 == end){
Range g = new Range(begin, end2);
return g;
}
else if(begin2 > begin && end2 == end){
Range g = new Range(begin2, end2);
return g;
}
// Wrong if
else if(begin2 > begin && end < end2){
if(begin < end2 && begin2 < end && end2 - begin2 > begin)
{
Range g = new Range(begin2, end);
return g;
}
else if(begin < end2 && end < end2){
Range g = new Range(0.0,0.0);
return g;
}
else{
Range g = new Range(0.0, 0.0);
return g;
}
}
else if(begin2 < begin && end > end2){
Range g = new Range(begin, end2);
return g;
}
//
else if(begin2 > end || begin2 < begin){
Range g = new Range(0.0,0.0);
return g;
}
else{
Range g = new Range(0.0,0.0);
return g;
}

}
}
Binary file added RangeTest.class
Binary file not shown.
86 changes: 86 additions & 0 deletions RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import junit.framework.TestCase;

public class RangeTest extends TestCase {


public void testNewRangeContains() {
Range r = new Range(0,2);
assertEquals(true, r.contains(0));
assertEquals(true, r.contains(1));
assertEquals(false, r.contains(2));

}
public void testNewWidth(){
Range r = new Range(0,2);
assertEquals(2.0, r.getWidth());
}
public void testMinMax(){
Range r = new Range(0,2);
assertEquals(0.0, r.getMin());
assertEquals(2.0, r.getMax());
}
public void testIntersectionEqual(){
Range r = new Range(1.0,3.0);
Range s = new Range(1.0,3.0);
Range intersect = r.intersection(s);
assertEquals(1.0, intersect.getMin());
assertEquals(3.0, intersect.getMax());
}
public void testIntersectionNotEqual(){
Range r = new Range(1.0, 3.0);
Range s = new Range(5.0, 10.0);
Range intersect = r.intersection(s);
assertEquals(0.0, intersect.getMin());
assertEquals(0.0, intersect.getMax());
}
public void testIntersectionWithin(){
Range r = new Range(2.0, 4.0);
Range s = new Range(1.0, 10.0);
Range intersect = r.intersection(s);
assertEquals(2.0, intersect.getMin());
assertEquals(4.0, intersect.getMax());
}
public void testIntersectionWithin2(){
Range r = new Range(1.0, 10.0);
Range s = new Range(2.0, 4.0);
Range intersect = r.intersection(s);
assertEquals(2.0, intersect.getMin());
assertEquals(4.0, intersect.getMax());
}
public void testIntersectionBeginEqual(){
Range r = new Range(2.0, 4.0);
Range s = new Range(2.0, 6.0);
Range intersect = r.intersection(s);
assertEquals(2.0, intersect.getMin());
assertEquals(4.0, intersect.getMax());
}
public void testIntersectionBeginEqual2(){
Range r = new Range(2.0, 6.0);
Range s = new Range(2.0, 4.0);
Range intersect = r.intersection(s);
assertEquals(2.0, intersect.getMin());
assertEquals(4.0, intersect.getMax());
}
public void testIntersectionEndEqual(){
Range r = new Range(2.0, 6.0);
Range s = new Range(1.0, 6.0);
Range intersect = r.intersection(s);
assertEquals(2.0, intersect.getMin());
assertEquals(6.0, intersect.getMax());
}
public void testIntersectionEndEqual2(){
Range r = new Range(1.0, 4.0);
Range s = new Range(2.0, 4.0);
Range intersect = r.intersection(s);
assertEquals(2.0, intersect.getMin());
assertEquals(4.0, intersect.getMax());
}
public void testIntersectionOverlap(){
Range r = new Range(1.0, 3.0);
Range s = new Range(2.0, 4.0);
Range intersect = r.intersection(s);
assertEquals(2.0, intersect.getMin());
assertEquals(3.0, intersect.getMax());
}
}