From 1e1700ffa66a20b045621c911b3393855e8c22ab Mon Sep 17 00:00:00 2001 From: John Vonelli Date: Tue, 3 Mar 2015 11:52:58 -0500 Subject: [PATCH] Submission for the Testing Lab --- Answers.md | 22 +++++++++++ Average.class | Bin 0 -> 653 bytes Average.java | 25 +++++++++++++ AverageTest.class | Bin 0 -> 1285 bytes AverageTest.java | 53 ++++++++++++++++++++++++++ Range.class | Bin 0 -> 1891 bytes Range.java | 92 ++++++++++++++++++++++++++++++++++++++++++++++ RangeTest.class | Bin 0 -> 2837 bytes RangeTest.java | 86 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 278 insertions(+) create mode 100644 Answers.md create mode 100644 Average.class create mode 100644 Average.java create mode 100644 AverageTest.class create mode 100644 AverageTest.java create mode 100644 Range.class create mode 100644 Range.java create mode 100644 RangeTest.class create mode 100644 RangeTest.java diff --git a/Answers.md b/Answers.md new file mode 100644 index 0000000..21a6221 --- /dev/null +++ b/Answers.md @@ -0,0 +1,22 @@ +# Testing Lab Answers +### John Vonelli + +** Question 1 **: Three mistakes that we can make when using an array are as follows. When determining the type of the class, if you would want to have values inserted as a *double* and you would accidentally initialize the array as an *integer*, that would truncate your information so it would fit into the *integer*. Another mistake that one could make when using an array is that you could mistakenly add information to the wrong variable in the array. For example, if you were to have values that was supposed to be added to `array[0]`, but accidentally added to `array[1]`, you could distort your variables and information within your array. Lastly, it is possible that you could use `{}` instead of `[]` when initializing the array, causing a syntax error. + +**Question 2**: When making a new `Scoreboard()`, there are no variables and would have no new information besides zero values. When there is a new instance of `Scoreboard()` with one mutation, that would signify that there would be one value within that instance of the class. So the user would be able to utilize the `isHighScore()`, the `getName()`, the `getScore()`, and the `getNumScores()` methods to recieve information. When there is a new instance of `Scoreboard()` with multiple mutations, that would mean that the instance of the class would hold multiple values and information. The user then would be able to utilze the methods mentioned above to access and to understand that information. + +**Question 3**: Here are the answers to the testing questions for the `Range` class. + +- **1**. A brand new instance of the class would have zero values for the variables, and the class would be ready to be utilized. +- **2**. Besides initializing the constructor `Range()` (which you could initialize to `Range(0,2)`), there are no other mutators that I could manipulate in this class. Thus, there are no other simplier mutations possible for this class. +- **3**. We can check the other methods to find out other information for the instance of the class. +- **4**. The boundary conditions for the `Range()` constructor are as follows. The lower boundary (start) of `Range()` is inclusive, while the upper boundary (stop) of `Range()` is exclusive. So for example, if you initialize `Range(0,2)`, then the range will be valid for 0 through 1. + + + + + + + + + diff --git a/Average.class b/Average.class new file mode 100644 index 0000000000000000000000000000000000000000..094281f1319e13faf6e8b6604cbfe42b5dab59e7 GIT binary patch literal 653 zcmY+B-%8^^7{$-zPus*aty*1o*S}Y4F6@nWiXi?0p(=|@Veg!#p{CYGYSLHm9ef5s z1V!+|2k@c9Gm{`LfywuMIp;TLChs4wZvZy2?83%x2NvelvQWli8A}4@O?D+9_66)P z$%ZNGBZ1O(JdD#FeqLK|3s`$eHxj6|;$d`>U3H?-U)dROGSx~#IcUpKtomYTr5Evy zfYaI?Mw;IIWG~OgI85iB zCD|y94r3L;E8H7>IhGz=On4}v?4bfjp!~(ItMAQ$9QK;0oqiOiSm8a`yc~lM9lD~4 zZwuT66I?xZ2QXOywcrIJ@SkA><}=JkZK!gcq5(u%1UVG@#QB_fxeYbc*$GTinIr#D zZE`jf{Ck428Y(6$(>nhT>}!$3EG`<%qoA|ggvJ7@s%d8DZ=+(Sz@O?90F8jmJJ|jM z3qv)x$phUcRP3ByrQ2uh`nSl9f3`|%e2&iaw(+<${kt?l#3UjMoOqAO)4>gkZ9ZtFxJ7+iPI_k3|B7n zAGmY_L=$!G(qAHbV|-6%I@3gmv-oc3JLi4Qcjm{R&tC!DK|Y2QG7-$i5I{znYzzaK zlhM4g@pS*m&&!X$WobbvB)Ns3T+1nigp(-+$3ywv3cmevB4y+9z5G5zuo%ITfbzho z8TLbgU^=rW5ZW>ib%A)$&}stpRz4iKO+%~l`r&k`Bxe_6pMT|a zrpW20i^ZZ`i)x35?nOgsRxrl*OEup_fso9!L(FsZf<8QZ4)KXW0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^3`K3>Rh|A}I&PF|~zsSdO)M8{<+Ie`(@9KVs-@VoT=Ru*DkxrX8C`$`}K(SGwS)z%0H5-g@d&< zIBGuPd1C36bYx2QWnQC^c14A2hhE`P=m80n5QgTY@NBm0Gl+#w*yz(gratpO%Q82= zL~bDJUzvFwyHDf}FAMmvk~qT8!vr7RBo=vjm-u{FxmV%JItut0Gq{Oa+`=5bMiCEj z6um>fnsJf!EciD5UXTFKd@$)xMaj|#mM0;eZg<>2`};y<@s?im{Ejo_R!-9F^6!M z8ARwt58dq{ey+NFR1Oh!Bb1AfJf7%NLF6!l?x$iHnI*@Wb{ywVtWFL&dxyADU@HyG F{0(^bJi-6~ literal 0 HcmV?d00001 diff --git a/Range.java b/Range.java new file mode 100644 index 0000000..038c850 --- /dev/null +++ b/Range.java @@ -0,0 +1,92 @@ +public class Range{ + private double begin = 0.0; + private double end = 0.0; + private double begin2 = 0.0; + private double end2; + private double width = 0.0; + private double result = 0.0; + + public Range(double start, double stop){ + begin = start; + end = stop; + } + public boolean contains(double value){ + if(value >= begin && value < end){ + return true; + } + else{ + return false; + } + } + public double getWidth(){ + return Math.abs(begin - end); + } + public double getMin(){ + return begin; + } + public double getMax(){ + return end; + } + public Range intersection(Range other){ + begin2 = other.getMin(); + end2 = other.getMax(); + + if(begin == begin2 && end == end2){ + Range g = new Range(begin2, end2); + return g; + } + else if(begin2 > begin && end2 < end){ + Range g = new Range(begin2, end2); + return g; + } + else if(begin2 < begin && end2 > end){ + Range g = new Range(begin, end); + return g; + } + else if(begin2 == begin && end2 > end){ + return new Range(begin2, end); + } + else if(begin2 == begin && end2 < end){ + Range g = new Range(begin2, end2); + return g; + } + else if(begin2 < begin && end2 == end){ + Range g = new Range(begin, end2); + return g; + } + else if(begin2 > begin && end2 == end){ + Range g = new Range(begin2, end2); + return g; + } + // Wrong if + else if(begin2 > begin && end < end2){ + if(begin < end2 && begin2 < end && end2 - begin2 > begin) + { + Range g = new Range(begin2, end); + return g; + } + else if(begin < end2 && end < end2){ + Range g = new Range(0.0,0.0); + return g; + } + else{ + Range g = new Range(0.0, 0.0); + return g; + } + } + else if(begin2 < begin && end > end2){ + Range g = new Range(begin, end2); + return g; + } + // + else if(begin2 > end || begin2 < begin){ + Range g = new Range(0.0,0.0); + return g; + } + else{ + Range g = new Range(0.0,0.0); + return g; + } + + } + } diff --git a/RangeTest.class b/RangeTest.class new file mode 100644 index 0000000000000000000000000000000000000000..6b3a7f921c4f5de6a421b12b03a15a4e9874a629 GIT binary patch literal 2837 zcmb`H=~CNP9L0~kf+K879LGS|(h$4=X3NrGh{1-2#7hDpr()1-wN>E5gVz2~R%Kh|G=|NbX{H9QYs6svx$`7)e~zW`jg zCocB`h~hy25AmItJ`&S)F-nWehA%VF+OX-%gsqt`bH^DBJA+l!w1d!we{TK=VGp6L5} zt-h`xT<5*0e`>B}D`s6YOcp6s1%9iLMXFu&#yGCOR}c`>f?*c4pA_5>lRdMpS8MuF z-Kdy5KQ^>7Pv9wohO@39+F4hu)a}wp=c6|UQB4Imdp}rFFxL5GTR$-z>G8`Sa%&gJ zj(Kc@jCO8x9&uY2OX*CnmbD*f$E!-CdZh0f!ug;yckxs^(^QOMT!FW_DkfVhwvknl z!;T-jD!#`P6?=FpR-UQIi%~&biYU=Qc^bJ-8|;1RT~+(2f2veJr1oiiR;y9e8_VTH z9tMtN13j@^{D7U)YBjxT8O?@xV+RMKa9FUV%FID3S7|gO<3H2N4ZZY^9p%=1X8}_% zaH7}k1TcO%1#_{sveMxx`@i13BJ_OR%D~tI5gS!TgOMRn%nn=JzGH^JnbBtYhroVg zoYz~Nr+8O*_a;6=`Hce?CV2HV7u}fTShWf;g=x+d9_4H{S?A(f;t#mq2E%ZFhBxm? z2G8NUfZvl0Sp#>HkE~%!Ap$RV`g!^QZeWl~0mL~IiV^EnTT!gt#?zmdG_rM2f1Nq9gE7 zbcCYUX?Yk4zG>_Il2Uj|3g4B&KT}xj-Vnl}FouM;ZR0|6{v4rVh?)!MkSIgeybEQF z#{oBq5^W}7l0fqmOVbU3l(57k(z1;d#VqD%zKc~;h;ig*8{$`EhA|w*2%&9I;aLmR zo?U`DNz5q%PV;{Ti$qCNxF6;ipIeyI%&&u)keI*NZf*$&*|0FeZGN_4TFq>MvaqkC zv&__8qRtUDh9x?ap_eVxE!)u`R&7T`t%EuvQIow<*?0lhY`ny_9sN?&dAhnl)J3AE zh`L171o01AgZpw!vnluMX@j z>FaHV#)-f}A6S9+zc~Adupw}`sU5M&vG z93!y95bU<0{@c8!dZQ9f{;>XQUY{_pdqjOo)MrG^6SdF-^{TusU5YBdsaK=+|E`vZ Y`kbgQi29PKuZX(;6{ySn61%YS4^;)e=Kufz literal 0 HcmV?d00001 diff --git a/RangeTest.java b/RangeTest.java new file mode 100644 index 0000000..927fe7b --- /dev/null +++ b/RangeTest.java @@ -0,0 +1,86 @@ +import junit.framework.TestCase; + +public class RangeTest extends TestCase { + + + public void testNewRangeContains() { + Range r = new Range(0,2); + assertEquals(true, r.contains(0)); + assertEquals(true, r.contains(1)); + assertEquals(false, r.contains(2)); + + } + public void testNewWidth(){ + Range r = new Range(0,2); + assertEquals(2.0, r.getWidth()); + } + public void testMinMax(){ + Range r = new Range(0,2); + assertEquals(0.0, r.getMin()); + assertEquals(2.0, r.getMax()); + } + public void testIntersectionEqual(){ + Range r = new Range(1.0,3.0); + Range s = new Range(1.0,3.0); + Range intersect = r.intersection(s); + assertEquals(1.0, intersect.getMin()); + assertEquals(3.0, intersect.getMax()); + } + public void testIntersectionNotEqual(){ + Range r = new Range(1.0, 3.0); + Range s = new Range(5.0, 10.0); + Range intersect = r.intersection(s); + assertEquals(0.0, intersect.getMin()); + assertEquals(0.0, intersect.getMax()); + } + public void testIntersectionWithin(){ + Range r = new Range(2.0, 4.0); + Range s = new Range(1.0, 10.0); + Range intersect = r.intersection(s); + assertEquals(2.0, intersect.getMin()); + assertEquals(4.0, intersect.getMax()); + } + public void testIntersectionWithin2(){ + Range r = new Range(1.0, 10.0); + Range s = new Range(2.0, 4.0); + Range intersect = r.intersection(s); + assertEquals(2.0, intersect.getMin()); + assertEquals(4.0, intersect.getMax()); + } + public void testIntersectionBeginEqual(){ + Range r = new Range(2.0, 4.0); + Range s = new Range(2.0, 6.0); + Range intersect = r.intersection(s); + assertEquals(2.0, intersect.getMin()); + assertEquals(4.0, intersect.getMax()); + } + public void testIntersectionBeginEqual2(){ + Range r = new Range(2.0, 6.0); + Range s = new Range(2.0, 4.0); + Range intersect = r.intersection(s); + assertEquals(2.0, intersect.getMin()); + assertEquals(4.0, intersect.getMax()); + } + public void testIntersectionEndEqual(){ + Range r = new Range(2.0, 6.0); + Range s = new Range(1.0, 6.0); + Range intersect = r.intersection(s); + assertEquals(2.0, intersect.getMin()); + assertEquals(6.0, intersect.getMax()); + } + public void testIntersectionEndEqual2(){ + Range r = new Range(1.0, 4.0); + Range s = new Range(2.0, 4.0); + Range intersect = r.intersection(s); + assertEquals(2.0, intersect.getMin()); + assertEquals(4.0, intersect.getMax()); + } + public void testIntersectionOverlap(){ + Range r = new Range(1.0, 3.0); + Range s = new Range(2.0, 4.0); + Range intersect = r.intersection(s); + assertEquals(2.0, intersect.getMin()); + assertEquals(3.0, intersect.getMax()); + } +} +