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

Fritz Testing Lab #11

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
21 changes: 21 additions & 0 deletions Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Average
{
private double sum = 0;
private int count = 0;

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

public double getAverage()
{
return sum/count;
}

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

public class AverageTest extends TestCase
{
public void testNewAverage()
{
Average avg = new Average();

avg.addValue(5.5);

assertEquals(1, avg.getCount());
assertEquals(5.5, 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 testMultipleValues()
{
Average avg = new Average();

avg.addValue(5.0);
avg.addValue(3.0);
avg.addValue(4.0);
avg.addValue(8.0);
avg.addValue(1.0);
avg.addValue(6.0);

assertEquals(6, avg.getCount());
assertEquals(4.5, avg.getAverage(), 0.001);
}

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

avg.addValue(5.5);
avg.addValue(-5.5);
avg.addValue(2.0);
avg.addValue(-2.0);
avg.addValue(1.5);
avg.addValue(-1.5);

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

public void testSameValues()
{
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, avg.getCount());
assertEquals(5.5, avg.getAverage(), 0.001);
}

}
37 changes: 37 additions & 0 deletions FritzAnswers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Testing Lab Jacob Fritz

**Question 1:** List three mistakes we can make when using an array.
1. Using 1 as the first index, not 0.
2. Going out of bounds when looping through an array.
3. Forgetting to create the array - only declaring it (int[ ] nums;).

**Question 2:** List at least one configuration of a Scoreboard for each of the scenarios below.
a) A new instance of the class.

```Scoreboard sb = new Scoreboard();```

b) An instance with a single mutation.

```sb.addScore(5);```

c) An instance with multiple mutations.

```sb.addScore(String name, int score)```

**Question 3:** Answer the "Testing Questions" descripted in the previous section.
a) What would a brand new instance of the class look like?

```Range r = new Range(0.0,2.0);```

b) What is the simplest mutation possible for the class?
```getMin()``` or ```getMax()```

c) What else can we do to an instance of the class?
Check to see if the range contains a value.
Get the width of the range.
Get the minimum number found in the range.
Get the maximum number found in the range.
Determine if a range intersects with another range.

d) What are the boundary conditions for the class?
The values entered must be doubles, and the values must be known when the class is created, as they cannot be changed later.
80 changes: 80 additions & 0 deletions Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
public class Range
{
private double min = 0.0;
private double max = 0.0;

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

if(start > stop)
max = start;
else
max = stop;
}

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

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

public double getMin()
{
return min;
}

public double getMax()
{
return max;
}

public Range intersection(Range other)
{
double newMin = 0;
double newMax = 0;

double minB = min;
double maxB = max;

boolean stopMin = false;
boolean stopMax = false;

while (stopMin == false)
{
if(other.contains(minB) == true)
{
newMin = minB;
stopMin = true;
}
else
minB++;
}

while (stopMax == false)
{
if(other.contains(maxB))
{
newMax = maxB;
stopMax = true;
}
else
maxB--;
}

Range newRange = new Range(newMin,newMax);

return newRange;
}

}
42 changes: 42 additions & 0 deletions RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import junit.framework.TestCase;

public class RangeTest extends TestCase
{
public void testNewRange()
{
Range r = new Range(2.0,0.0);
}

public void testContains()
{
Range r = new Range(2.0,0.0);
assertEquals(true, r.contains(1.5));
}

public void testWidth()
{
Range r = new Range(2.0,0.0);
assertEquals(2.0, r.getWidth());
}

public void testMin()
{
Range r = new Range(2.0,0.0);
assertEquals(0.0, r.getMin());
}

public void testMax()
{
Range r = new Range(2.0,0.0);
assertEquals(2.0, r.getMax());
}

public void testIntersection()
{
Range r1 = new Range(0.0,5.0);
Range r2 = new Range(1.0,4.0);
Range r3 = r1.intersection(r2);
assertEquals(1.0, r3.getMin());
assertEquals(4.0, r3.getMax());
}
}