diff --git a/Questions.md b/Questions.md new file mode 100644 index 0000000..a201937 --- /dev/null +++ b/Questions.md @@ -0,0 +1,24 @@ +# CSCI 121: Computer Science II +## Testing Lab +***Question 1*** +Three mistakes that can be made when using an array is forgetting that 0 is apart of the +array, everything in the array has to be the same type, and make sure that all parts of +the array are set to null. + +***Question 2*** +After one configuration of a Scoreboard for both getScore() and getAverage() in the +instance of a class both methods would be empty, or no values. In an instance with a +single mutation in getScore()there will be one value added, while getAverage() would still +be empty. In an instance with multiple mutations getScore() will have one added value for +the amount of times that the mutation occurs. getAverage() will have a value at this +point. + +***Question 3*** +What would a brand new instance of the class look like? +It would be empty with no values because they haven't been assigned yet. +What is the simplest mutation possible for the class? +There is no simple mutation possible for this class at this point. +What else can we do to an instance of the class? + +What are the boundary conditions for the class? +There are no boundary conditions, currently it is laced at 0 for testing. \ No newline at end of file diff --git a/scr/Average.java b/scr/Average.java new file mode 100644 index 0000000..18a3dc7 --- /dev/null +++ b/scr/Average.java @@ -0,0 +1,30 @@ +public class Average { + double sum = 0.0; + int count = 0; + + public Average() { + } + + public void addValue(double value) { + count += 1; + sum += value; + } + + public double getAverage() { + if (count == 0) { + return 0; + } + else { + return sum/count; + } + } + + public int getCount() { + + return count; + } +} + + + + \ No newline at end of file diff --git a/scr/AverageTest.java b/scr/AverageTest.java new file mode 100644 index 0000000..dd34a98 --- /dev/null +++ b/scr/AverageTest.java @@ -0,0 +1,61 @@ +import junit.framework.TestCase; + +public class AverageTest extends TestCase { + public void testNewAverage() { + Average avg = new Average(); + + assertEquals(0, avg.getCount()); + assertEquals(0.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 testFiveValuesnonzeroAverage() { + + Average avg = new Average(); + + avg.addValue(1); + avg.addValue(2); + avg.addValue(3); + avg.addValue(4); + avg.addValue(5); + + assertEquals(3.0, avg.getAverage(), 0.001); + assertEquals(5, avg.getCount()); +} + public void testFiveValuesZeroAverage() { + + Average avg = new Average(); + + avg.addValue(0); + avg.addValue(0); + avg.addValue(0); + avg.addValue(0); + avg.addValue(0); + + assertEquals(0.0, avg.getAverage(), 0.001); + assertEquals(5, avg.getCount()); + } + public void testFiveValuesAverage() { + + Average avg = new Average(); + + avg.addValue(2); + avg.addValue(2); + avg.addValue(2); + avg.addValue(2); + avg.addValue(2); + + assertEquals(2.0, avg.getAverage(), 0.001); + assertEquals(5, avg.getCount()); + } +} + + + \ No newline at end of file diff --git a/scr/Range.java b/scr/Range.java new file mode 100644 index 0000000..372ec67 --- /dev/null +++ b/scr/Range.java @@ -0,0 +1,41 @@ +public class Range { + private double min; + private double max; + + public Range(double start, double stop) { + if (start < stop) { + min = start; + } + else { + min = stop; + } + if (stop > start) { + max = stop; + } + else { + max = start; + } + } + + public boolean contains (double value) { + return true; + } + + public double getWidth() { + return 0.0; + } + + public double getMin() { + return min; + } + + public double getMax() { + return max; + } + + public Range intersection(Range other) { + return new Range(0.0, 0.0); + } +} + + \ No newline at end of file diff --git a/scr/RangeTest.java b/scr/RangeTest.java new file mode 100644 index 0000000..c82427a --- /dev/null +++ b/scr/RangeTest.java @@ -0,0 +1,22 @@ +import junit.framework.TestCase; + +public class RangeTest extends TestCase { + public void testNewRange() { + Range rng = new Range(0.0, 0.0); + } + + public void testMin() { + Range r1 = new Range(1.0, 10.0); + assertEquals(1.0, r1.getMin(), 0.001); + Range r2 = new Range(5.0, -1.0); + assertEquals(-1.0, r2.getMin(), 0.001); + } + + public void testMax() { + Range r1 = new Range(1.0, 10.0); + assertEquals(10.0, r1.getMax(), 0.001); + Range r2 = new Range(5.0, -1.0); + assertEquals(5.0, r2.getMax(), 0.001); + } + +} \ No newline at end of file