From a9281f0b248f922563bc1c47c7bb73e9b54fe188 Mon Sep 17 00:00:00 2001 From: Hailey Kester Date: Thu, 12 Feb 2015 16:13:12 -0500 Subject: [PATCH] Lab Testing-Lab done!!! --- Answers.md | 17 ++++++++++++ src/Average.java | 30 +++++++++++++++++++++ src/AverageTest.java | 62 ++++++++++++++++++++++++++++++++++++++++++ src/Range.java | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/RangeTest.java | 58 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 231 insertions(+) create mode 100644 Answers.md create mode 100644 src/Average.java create mode 100644 src/AverageTest.java create mode 100644 src/Range.java create mode 100644 src/RangeTest.java diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..3881e41 --- /dev/null +++ b/Answers.md @@ -0,0 +1,17 @@ +# CSC1 121 Hailey Kester 2/12/15 +##Testing lab + +**Question1:** List three mistakes we can make when using an array. + +**Answer1:** Three mistakes that can be made using using an array would be that you can forget to use an index in order to store the values into an array, forgetting that an array always starts at 0 instead of 1, and lastly you /home/kester/cs121/Testing-Lab/Answers.mdcan try to store a type that is not compatible with the array type; which will not working because the types need to be consistant. + +**Question 2:** List at least one configuration of a `Scoreboard` for each of the above scenarios. + +**Answer 2:** One configuration of a `Scoreboard` for each of the above scenarios would be for a new instance of the class, there would be an empty array because there is no values inputed yet. With an instance with a single mutation, the configuration would be one item added to beginning of score array and adding array. For an instance with multiple mutations, there would be a mutliple of scores in the array and they would be in array order. + +**Question 3:** Answer the "Testing Questions" descripted in the previous section. + +**Answer 3:** What would a brand new instance of the class look like? A brand new instance of the class would look like a new `range` set to 0, which would set a new `range` array. +What is the simplest mutation possible for the class? The `range` class does not have any mutators so there is no simplest mutation possible for the class. +What else can we do to an instance of the class? For the range class we can compute the min and max of the range and check to see if they are the starting and stopping point, we can also check the width of the range to see the difference between the min and the max. +What are the boundary conditions for the class? The boundary conditions for the class would be the `getMin` and `getMax` because they determine our starting and stoping point of the range. \ No newline at end of file diff --git a/src/Average.java b/src/Average.java new file mode 100644 index 0000000..aee50df --- /dev/null +++ b/src/Average.java @@ -0,0 +1,30 @@ +public class Average { + private double sum = 0.0; + private int count = 0; + + public Average() { + + } + + public void addValue(double value) { + count += 1; + sum += value; + + + } + + public double getAverage() { + if (count == 0) { + return 0; + } + + + return sum/count; + } + + public int getCount() { + + return count; + } +} + diff --git a/src/AverageTest.java b/src/AverageTest.java new file mode 100644 index 0000000..2029482 --- /dev/null +++ b/src/AverageTest.java @@ -0,0 +1,62 @@ +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 testFiveValuesNonzeroAverage() { + Average avg = new Average(); + + avg.addValue(2.0); + avg.addValue(4.5); + avg.addValue(6.0); + avg.addValue(8.5); + avg.addValue(10.0); + + assertEquals(6.2, avg.getAverage(), 0.001); + assertEquals(5, avg.getCount()); + + } + + public void testFiveValuesZeroAverage() { + Average avg = new Average(); + + avg.addValue(0.0); + avg.addValue(0.0); + avg.addValue(0.0); + avg.addValue(0.0); + avg.addValue(0.0); + + assertEquals(0.0, avg.getAverage(), 0.001); + assertEquals(5, avg.getCount()); + + } + + public void testFiveValuesSame() { + Average avg = new Average(); + + avg.addValue(2.2); + avg.addValue(2.2); + avg.addValue(2.2); + avg.addValue(2.2); + avg.addValue(2.2); + + assertEquals(2.2, avg.getAverage(), 0.001); + assertEquals(5, avg.getCount()); + + } + + +} diff --git a/src/Range.java b/src/Range.java new file mode 100644 index 0000000..624163b --- /dev/null +++ b/src/Range.java @@ -0,0 +1,64 @@ +public class Range { + private double start; + private double stop; + + public Range(double start, double stop) { + if (start <= stop) { + this.start = start; + this.stop = stop; + } + else { + this.start = stop; + this.stop = start; + } + + + + } + + public boolean contains(double value) { + if ((value >= start) && (value < stop)) { + return true; + } + return false; + + + } + + public double getWidth() { + return stop-start; + + } + + public double getMin() { + return start; + + } + + public double getMax() { + return stop; + } + + public Range intersection(Range other) { + double newMin = 0; + double newMax = 0; + if (other.contains(start)) { + newMin = start; + } + + if (other.contains(stop)) { + newMax = stop; + } + + if (contains(other.getMin())) { + newMin = other.getMin(); + } + + if (contains(other.getMax())) { + newMax = other.getMax(); + } + + + return new Range(newMin, newMax); + } +} diff --git a/src/RangeTest.java b/src/RangeTest.java new file mode 100644 index 0000000..3a37741 --- /dev/null +++ b/src/RangeTest.java @@ -0,0 +1,58 @@ +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(10.0, 1.0); + assertEquals(10.0, r1.getMax(), 0.001); + + Range r2 = new Range(-1.0, 5.0); + assertEquals(5.0, r2.getMax(), 0.001); + + } + + public void testWidth() { + Range r1 = new Range(10.0, 1.0); + assertEquals(9.0, r1.getWidth(), 0.001); + + Range r2 = new Range(5.0, -1.0); + assertEquals(6.0, r2.getWidth(), 0.001); + + } + + public void testBooleanContains() { + Range r1 = new Range(10.0, 1.0); + assertTrue(r1.contains(4.0)); + + Range r2 = new Range(5.0, -1.0); + assertFalse(r2.contains(10.0)); + + assertFalse(r1.contains(10.0)); + + + } + + public void testRangeIntersection() { + Range r1 = new Range(10.0, 1.0); + Range r2 = new Range(5.0, -1.0); + Range r3 = r1.intersection(r2); + + assertEquals(4.0, r3.getWidth(), 0.001); + } + + + + +}