From 3510d2b54877570c9d2a62bb9ca96ca52d7ebb70 Mon Sep 17 00:00:00 2001 From: Zachary Kitto Date: Tue, 29 Jun 2021 21:45:40 -0400 Subject: [PATCH 1/2] Passed all tests except 1 --- .../java/io/zipcoder/StringsAndThings.java | 58 ++++++++++++++++-- .../io/zipcoder/StringsAndThings.class | Bin 0 -> 2353 bytes .../ContainsEqualNumberOfIsAndNotTest.class | Bin 0 -> 1323 bytes .../stringsandthings/CountTripleTest.class | Bin 0 -> 1321 bytes .../stringsandthings/CountYZTest.class | Bin 0 -> 1372 bytes .../stringsandthings/GIsHappyTest.class | Bin 0 -> 1210 bytes .../stringsandthings/RemoveStringTest.class | Bin 0 -> 1308 bytes 7 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 target/classes/io/zipcoder/StringsAndThings.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/CountTripleTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/CountYZTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class create mode 100644 target/test-classes/io/zipcoder/stringsandthings/RemoveStringTest.class diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 073467a..aaf295d 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -15,7 +15,14 @@ public class StringsAndThings { * countYZ("day fyyyz"); // Should return 2 */ public Integer countYZ(String input){ - return null; + int countOfYZ = 0; + String[] inputToArrayOfWords = input.split(" "); + for (String word : inputToArrayOfWords) { + if (word.endsWith("y") || word.endsWith("z")) { + countOfYZ += 1; + } + } + return countOfYZ; } /** @@ -28,7 +35,8 @@ public Integer countYZ(String input){ * removeString("Hello there", "x") // Should return "Hello there" */ public String removeString(String base, String remove){ - return null; + String newString = base.replaceAll(remove, ""); + return newString; } /** @@ -40,7 +48,28 @@ public String removeString(String base, String remove){ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true */ public Boolean containsEqualNumberOfIsAndNot(String input){ - return null; + boolean isAppearsSameNumberOfTimesAsNot = true; + int isCount = 0; + int notCount = 0; + int numberOfIsIndex = 0; + int numberOfNotIndex = 0; + int numberOfIs = 0; + int numberOfNot = 0; + while ((numberOfIsIndex = input.indexOf("is", isCount)) != -1) { + isCount = numberOfIsIndex + 2; + numberOfIs++; + } + while ((numberOfNotIndex = input.indexOf("not", notCount)) != -1) { + notCount = numberOfNotIndex + 2; + numberOfNot++; + } + if (numberOfIs == numberOfNot) { + isAppearsSameNumberOfTimesAsNot = true; + } + else { + isAppearsSameNumberOfTimesAsNot = false; + } + return isAppearsSameNumberOfTimesAsNot; } /** @@ -51,7 +80,17 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ * gHappy("xxggyygxx") // Should return false */ public Boolean gIsHappy(String input){ - return null; + boolean gIsHappy = false; + char[] inputToCharArray = input.toCharArray(); + for (int i = 0; i < inputToCharArray.length; i++) { + if (inputToCharArray[i] == 'g' && (inputToCharArray[i - 1] == 'g' || inputToCharArray[i + 1] == 'g')) { + gIsHappy = true; + } + else if (inputToCharArray[i] == 'g' && (inputToCharArray[i - 1] != 'g' || inputToCharArray[i + 1] != 'g')) { + gIsHappy = false; + } + } + return gIsHappy; } @@ -62,7 +101,14 @@ public Boolean gIsHappy(String input){ * countTriple("xxxabyyyycd") // Should return 3 * countTriple("a") // Should return 0 */ - public Integer countTriple(String input){ - return null; + public Integer countTriple(String input) { + int numberOfTriples = 0; + char[] inputToArray = input.toCharArray(); + for (int i = 0; i < inputToArray.length - 2; i++) { + if (inputToArray[i] == inputToArray[i + 1] && inputToArray[i] == inputToArray[i + 2]) { + numberOfTriples += 1; + } + } + return numberOfTriples; } } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class new file mode 100644 index 0000000000000000000000000000000000000000..7896d4c019e5eeb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u<(G0!B0>ndq|`5}@0KKMLA7C814X`Lpl8B#h+&m2!vxQlx&!J7OTJWF6wOje6B zt3}y;!jY8e%uR41fnawb{0=6CdR`n?`@~ycoujQg_zTNP+{q7dYo+Jtm#6}y8|Y~q zw1xOaaP=gj-?zJZ4rh44DISvdGACLks)wAY+J@v*3rVttB-uhTN(srUrxQ`Kg=7bm N7LowQMGhXq*xzYh(+~gv literal 0 HcmV?d00001 diff --git a/target/test-classes/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.class b/target/test-classes/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.class new file mode 100644 index 0000000000000000000000000000000000000000..556ec648ddd0173f22453fac00953e644e289eef GIT binary patch literal 1323 zcmb7DZBG+H5Pr5Tv|JA;MG+Jb3PLH$$&0TTA`nSPnvzJ!0H(EUm(>8~*) zi*q%G)FuTo^p~X)mEfc<+$yiz-UP zUTZ@fIIf_?exXsfy$EWNZp0ftxflk^$NU4gY_1Ni4aczsSCo)zLy5>QVJ!WJy3Ang zI)U2|TT&Ne=Ef^6XlfHV3^0sd*8&rL=x4}M!@LRl=)NW%V=;{-6U$gh95es` literal 0 HcmV?d00001 diff --git a/target/test-classes/io/zipcoder/stringsandthings/CountTripleTest.class b/target/test-classes/io/zipcoder/stringsandthings/CountTripleTest.class new file mode 100644 index 0000000000000000000000000000000000000000..29d3cfe89a19ec698f6f56f4b5783c566258b309 GIT binary patch literal 1321 zcmbW0YflqF6o%jFZA-gKDHr7`1(dcRtALt_F+rjUNtHxMgP+WFJCr45w{Ewj`man> zh$j93f0Xgv?Mll{6ZXUGnKN_V=bSS$zkYxJ31AgZQqVD@VK#*bX8MrETncw_FNt~I zlTV?5ViF5UENZx~VM!p<^jyoXHP`Lx&c1I5OqDFh_+&Lqr>b0I``r4PK;oHYTi$bl zXuePuh;4AAK!3@y)tlB~MY%h&Ql}?da!gq-OV{$}p)=;~TZAl~frLp&yUJB2VQe@p z+uL!i2IExIBQ)MrUaKK6`j#u!p(m9k?Re6&9Gjv9x;5jV#q5k1YR_>M12g7X zt%m|h)ov)$Q&oY%(t$jZMqS!9W7GCjO}T!B()3!g&fp%!Fp=|m%NG$V0;z4M<(lf1 z=PIpT z9+&AJ-FmaBTxOulzIgSL7=}vG6 ziBonA<4m%jB~8$Z;4gSG08d>6Cr-hASAxd~9;fI8L6g@4-?<2mo`O?Xf^!7V5Ijrp M+_k{dtUH3-AHtao{r~^~ literal 0 HcmV?d00001 diff --git a/target/test-classes/io/zipcoder/stringsandthings/CountYZTest.class b/target/test-classes/io/zipcoder/stringsandthings/CountYZTest.class new file mode 100644 index 0000000000000000000000000000000000000000..27178e441080925aa59e674cb2fb937740d251ba GIT binary patch literal 1372 zcmbtTYfsZ)7(MT9Eu+c+CxAzIo`;4x1^4qvVXhDTc%WiFj}ppZM$cmb ziz=2>EGsY+JQOH+zH8YHZ^N$d9fg6wRK;?PGpki|>e4lK|EaGFF${aO=gBFPR(pqP1g#~aWdl{StQXfk;EcQyUr>_7@JOD`}-gE zr00_`>q$Ro35>sI);f_@%d?2MVcU*x`j%r8kYsMdI1Z@Hcr6bdS8`CRB{(a@vFujh zhrP$fSPE!&q3>4s~YH9s($^sI|2R@hCndYN}kAiwJb zZcV(ZJxL)hf~q;3#6l(rvE@{{~YPB$Rrryp9c2z6EVTj zVw};KWh}xR|BLBxD#P69P_~l2K<=IX1(}6!P_`GBE}$mxBisZOlg21ijFD)Zr-_J4 z??A*C6t|?@ezNB#P5A_TU`2YX_ literal 0 HcmV?d00001 diff --git a/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class b/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class new file mode 100644 index 0000000000000000000000000000000000000000..97d69c05d93af48f51dd343f570612e004b2bfd8 GIT binary patch literal 1210 zcmb7@YflqV5Qg8=7FxCov_%n=i`=9w%F4wn#-x~_CJiRiG?8zo<+vQO>^6Hbt^dkI z!D!+S@JAWvY!`RIK*E>ZnK?7>Gc$Yk_n#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 From 7f559cecc7a440009cf96d660e4db2be6dd64e5a Mon Sep 17 00:00:00 2001 From: Zachary Kitto Date: Mon, 5 Jul 2021 12:56:06 -0400 Subject: [PATCH 2/2] accounted for extra test cases --- .../java/io/zipcoder/StringsAndThings.java | 5 ++++- .../stringsandthings/GIsHappyTest.java | 12 ++++++++++++ .../io/zipcoder/StringsAndThings.class | Bin 2353 -> 2385 bytes .../stringsandthings/GIsHappyTest.class | Bin 1210 -> 1481 bytes 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index aaf295d..f8ea29f 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -82,13 +82,16 @@ public Boolean containsEqualNumberOfIsAndNot(String input){ public Boolean gIsHappy(String input){ boolean gIsHappy = false; char[] inputToCharArray = input.toCharArray(); - for (int i = 0; i < inputToCharArray.length; i++) { + for (int i = 1; i < inputToCharArray.length - 1; i++) { if (inputToCharArray[i] == 'g' && (inputToCharArray[i - 1] == 'g' || inputToCharArray[i + 1] == 'g')) { gIsHappy = true; } else if (inputToCharArray[i] == 'g' && (inputToCharArray[i - 1] != 'g' || inputToCharArray[i + 1] != 'g')) { gIsHappy = false; } + else if (inputToCharArray[0] == 'g' && inputToCharArray[1] == 'g') { + gIsHappy = true; + } } return gIsHappy; } diff --git a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java index 020cd3d..29ba65c 100644 --- a/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java +++ b/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java @@ -33,7 +33,19 @@ public void gIsHappyTest2(){ @Test public void gIsHappyTest3(){ Boolean actual = stringsAndThings.gIsHappy("xxggyygxx"); + Assert.assertFalse(actual); + } + + @Test + public void gIsHappyTest4(){ + Boolean actual = stringsAndThings.gIsHappy("ggxggyyxxgg"); Assert.assertTrue(actual); } + @Test + public void gIsHappyTest5(){ + Boolean actual = stringsAndThings.gIsHappy("gxxyyxxg"); + Assert.assertFalse(actual); + } + } diff --git a/target/classes/io/zipcoder/StringsAndThings.class b/target/classes/io/zipcoder/StringsAndThings.class index 7896d4c019e5eeb71b9f669efa8067e75c7d4449..37ea7f6ee8697e85b278f6287c66f4d75213c4d1 100644 GIT binary patch delta 278 zcmXAjy-EX75QV?%op6_x1YKQ4j0<96Ay-7!Rf~NA3mgA`0)YfXG#ZIWIvab7?Q9gA zw6PH@-@($CQ75sP`IvL&%)CWkQUBJ>nGj0}=-PbgoyxXk5{v(o<|~cj(JkC>`dHGj zvlkKtX%4Y6z`Eiyfz5lw-VWzw|8Ffx{vf9J`&9j)+}Cu=q}F9dweB#&E{;7W*k_dk z);Ur-=7du&sL@ibL!DUNTdBSma?TnFqJu6|Olu!dm066&-I3z8J8sA{&N8ohg!>^h hjt#RYiHsMupfPi)ww4;N^!l|fwOLWl=oH_<;U915E9d|K delta 246 zcmca8v{7h73A;4ID+Xo;Rt5%!L}pvA$91#F diff --git a/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class b/target/test-classes/io/zipcoder/stringsandthings/GIsHappyTest.class index 97d69c05d93af48f51dd343f570612e004b2bfd8..ca313ec8b9902c542dda8b0537ab5be33764aa3e 100644 GIT binary patch literal 1481 zcmb7@dr#9)7{;G71}$B=Y$)Eih}?Ej%FP=f224z?tj9@{*qJ|h21~H7Zii}LM8gh83 z;SrWp7;;@!v7%yC#hQY31&;+r{lK%GiofF=6^>;fFqOAmZ{ELB-a<=wJbEt;M!^RO5Xj%`A6mmuK~rgOwy z4q?20>%TE;wX=fd2PF3UR#2}A+<9Mj0{he|+P+Q69mjD4Gq7EUilliJsf3ZsVLi8nt)egnAj(oi%r@`8R zTldP=o-G|ow!hbsoIpnkV*(S`S*~LgNzUGAR4R>zjwg7k;F*r+*if*kV+${65qIV0 zwoC@)(X%ra1QKkLi7W}ItTkhSOgr=1FF<1=x89Xbta2cgLTd#U(`|0HF3e`8trQuY zjC8`HfL?0(Uo@+Adc;e0NMQ6acYNRS2-M7GQ1Ilbc=}M@y+o_FXI6a+GrapF{3itO zJ{@DEFs8qJ-e6{M6=xgrj*`J7g zxIo`G#3K#)yMf3AagmN5>f8+}_nMj$|26m7CHqp@uZXAm&oPkCokRH!HBufX7u3-> zQIhjW_3>6$sIEc9B&ImsKhAWMbH58`Fyd&PoJn$~$eHeeGt-5WxP~)J&Kx=OJ#Zd$ m;ph?PifZqGY%c^L1iBv!^un7(o#5MsblNwIG){! zBQ4F{d+#~t+xrnLyob-9#T$Sj?tHAF?I87Gq3uDTcP|2*^G<) z(fV#E9svmcN)S7nJ<+UTK9Eswi@P!>Aiy@OGQEu*M4SYw^jh>j%Xp-{`hIX1AYAgR z!e67NX?2s`Ewb-29qViblC?@kjY{3*Bf|@eybl)*G)ed)#fG$3kou)%QcRLoS}TxR a1?i>KoVatsE&QLB64;@ky8>|EFp^)BF)4ij