From ed0b3e5e7c73dc7991f428dc71386b3c8126dd29 Mon Sep 17 00:00:00 2001 From: Emily Mudd Date: Thu, 26 Feb 2015 13:49:09 -0500 Subject: [PATCH 1/3] Testing Lab --- AnswersTestingLab.md | 30 ++++++++++++++++++++++++++++++ src/.DS_Store | Bin 0 -> 6148 bytes src/._.DS_Store | Bin 0 -> 4096 bytes src/Average.java | 27 +++++++++++++++++++++++++++ src/AverageTest.java | 18 ++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 AnswersTestingLab.md create mode 100644 src/.DS_Store create mode 100644 src/._.DS_Store create mode 100644 src/Average.java create mode 100644 src/AverageTest.java diff --git a/AnswersTestingLab.md b/AnswersTestingLab.md new file mode 100644 index 0000000..6126069 --- /dev/null +++ b/AnswersTestingLab.md @@ -0,0 +1,30 @@ +**Question 1:** Arrays start at zero, if you forget this your counting will be off. +Forgetting to initialize objects in arrays. An array in java is really an object reference, +creating an array with new will result in an empty reference. It is also important to keep +in mind that all elements in an array are set to null. In order to have a complete array, +each element must be linked to a real object reference. In java, an array can not be of +mixed types. When looping over arrays you have to be careful to remember to set the +condition when i is less than length. + +**Question 2:** +For a new instance of the class, it will look empty meaning there is no values in the two +arrays. It will have the arrays but we haven't put anything in them yet. + +For an instance of a single mutation, it will have added one item to the start of the +score and string array, everything else will be blank. + +For an instance with multiple mutations, will depend on scores, will be in sorted order. + +**Question 3:** +What would a brand new instance of class look like? +It would be empty because we haven't assigned values yet. + +What is the simplest mutation possible for the class? +There is actually nothing that can be mutated. + +What else can we do to an instance of the class? + + +What are the boundary conditions for the class? +Boundary conditions are what is right on the edge of being correct. This is most likely +to be where mistakes happens. Currently it is at 0 for testing. \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3c8ce378e9667be5cffe2fcd6c642772ff4d1b18 GIT binary patch literal 6148 zcmeHKyG{c^3>=3Pk)TLPxnF?99~@Cqq=paRLJ$&)6e&RJ>+)y(R+w3v$LXM@09&%> z*6Z25o8r6+z-BM&OJE9MLKotoFf`4}2R4d~(CQj39&nEfJfa;`f1eQd3|H8bw>hQ1a^*`p_x;OPPMpV znA4drQP%`^j!uWwow-izY;i-ex;yiwmctsyjHy5>&{yEZhg0=`-K&4N|My8bN(EAZ zKc#?;=hyQYKPh_a;N#S53;mY$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIk*Y|peR=07!nf1 z<{8=o(ZNuGRne&6Xb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeDP&ot`f#!iQ z7|4ZWWELwFr55Lx7A2=Dq~#Z7D`e)Cq~?`m=I15m4jn|NjF3{$U-y literal 0 HcmV?d00001 diff --git a/src/Average.java b/src/Average.java new file mode 100644 index 0000000..f99a8cb --- /dev/null +++ b/src/Average.java @@ -0,0 +1,27 @@ +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/src/AverageTest.java b/src/AverageTest.java new file mode 100644 index 0000000..21578f0 --- /dev/null +++ b/src/AverageTest.java @@ -0,0 +1,18 @@ +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()); + } +} \ No newline at end of file From 063efb713f9a851287a23a1b640a96646ab7ea96 Mon Sep 17 00:00:00 2001 From: Emily Mudd Date: Thu, 26 Feb 2015 14:03:13 -0500 Subject: [PATCH 2/3] Testing Lab with all files --- AnswersTestingLab.md | 1 + src/Range.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/RangeTest.java | 24 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 src/Range.java create mode 100644 src/RangeTest.java diff --git a/AnswersTestingLab.md b/AnswersTestingLab.md index 6126069..f5fc3b1 100644 --- a/AnswersTestingLab.md +++ b/AnswersTestingLab.md @@ -25,6 +25,7 @@ There is actually nothing that can be mutated. What else can we do to an instance of the class? + What are the boundary conditions for the class? Boundary conditions are what is right on the edge of being correct. This is most likely to be where mistakes happens. Currently it is at 0 for testing. \ No newline at end of file diff --git a/src/Range.java b/src/Range.java new file mode 100644 index 0000000..b9e7674 --- /dev/null +++ b/src/Range.java @@ -0,0 +1,44 @@ +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); + } + + +} diff --git a/src/RangeTest.java b/src/RangeTest.java new file mode 100644 index 0000000..1725c48 --- /dev/null +++ b/src/RangeTest.java @@ -0,0 +1,24 @@ +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 From 26f789e98d52ea8c97acdd50ece92e05b545fd9f Mon Sep 17 00:00:00 2001 From: Emily Mudd Date: Thu, 26 Feb 2015 14:30:31 -0500 Subject: [PATCH 3/3] Fixed AverageTest.java --- src/._AverageTest.java | Bin 0 -> 4096 bytes src/AverageTest.java | 63 ++++++++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 src/._AverageTest.java diff --git a/src/._AverageTest.java b/src/._AverageTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3b4467034e1a0f8b335f1dccccd95fb668fc753e GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vV)N~T z>R^}yRL+m4g%QYyii;=b=jtUE6y&7pg``%LxaKA2r)1`(0~M5(r0H5%8ycG!8Jb&K zn4lRk${h`X(GVC7fzc2c4S~@R7!85Z5Eu=C(GVC7fzc2c4FS{;0ChG&7!2e>GBS%5 zic*X7ON)|I71HvHvK2D(N>cMmGV}8ib8;#ba#GVu6q0fh^Rj_`VW_SlO`-Z9?iCpZ Hx&QwG)cGl% literal 0 HcmV?d00001 diff --git a/src/AverageTest.java b/src/AverageTest.java index 21578f0..80dab20 100644 --- a/src/AverageTest.java +++ b/src/AverageTest.java @@ -1,18 +1,55 @@ import junit.framework.TestCase; public class AverageTest extends TestCase { - public void testNewAverage(){ - Average avg = new Average(); + 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(2); + avg.addValue(4); + avg.addValue(6); + avg.addValue(8); + avg.addValue(10); + + assertEquals(6.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()); + } - 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 testFiveValuesTheSame(){ + Average avg = new Average(); + + avg.addValue(4); + avg.addValue(4); + avg.addValue(4); + avg.addValue(4); + avg.addValue(4); + + assertEquals(4.0, avg.getAverage(), 0.001); + assertEquals(5, avg.getCount()); + } } \ No newline at end of file