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 #20

Open
wants to merge 2 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
9 changes: 9 additions & 0 deletions lab_4_answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Lab 4 Answers

1. Three things that could go wrong when making an array include: passing the wrong type to the array, forgetting to increment the loop or incrementing wrong, or not giving each new scoreboard a different name.
2. With a new instance of the class, `Scoreboard` will be empty. With a single mutation, `Scoreboard` will have one name and one score. In an instance where there are 5 mutations, `Scoreboard` will have 5 names with five scores.
3. **Testing questions for `Range`:**
1. A brand new instance of the class would be empty and would contain no values.
2. The simplest possible mutaion possible would be adding one value to the range.
3. In an instance of a class the only other things we can do is use query methods on them.
4. The boundary conditions are numbers from 0 to > 10.
20 changes: 20 additions & 0 deletions src/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Average {
private double sum = 0.0;
private int count = 0;
private double avg = 0.0;

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

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

public int getCount() {
return count;
}

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

avg.addValue(5.5);

assertEquals(5.5, avg.getAverage(), 0.001);
assertEquals(1, avg.getCount());
}
public void testMultValue1() {
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 testMultValue2() {
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 testMultValue3() {
Average avg = new Average();

avg.addValue(2.0);
avg.addValue(2.0);
avg.addValue(2.0);
avg.addValue(2.0);
avg.addValue(2.0);

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

public Range(double start, double stop) {

}
public boolean contains(double value) {
return true;
}
public double getWidth() {
return 0.0;
}
public double getMin() {
return 0.0;
}
public double getMax() {
return 0.0;
}
public Range intersection(Range other) {
return ;
}
}