Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have added changes #62

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 74 additions & 22 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package io.zipcoder;


import javax.annotation.processing.SupportedSourceVersion;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author tariq
*/
Expand All @@ -11,58 +16,105 @@ public class StringsAndThings {
* but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not an alphabetic
* letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.)
* example : countYZ("fez day"); // Should return 2
* countYZ("day fez"); // Should return 2
* countYZ("day fyyyz"); // Should return 2
* countYZ("day fez"); // Should return 2
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
public int countYZ(String input) {
int count = 0;
Pattern regex = Pattern.compile("[yz](?!\\p{L})", Pattern.CASE_INSENSITIVE);
Matcher regexMatcher = regex.matcher(input);
while (regexMatcher.find()) {
count++;
}
return count;
}

/**
* Given two strings, base and remove, return a version of the base string where all instances of the remove string have
* been removed (not case sensitive). You may assume that the remove string is length 1 or more.
* Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".
*
* <p>
* example : removeString("Hello there", "llo") // Should return "He there"
* removeString("Hello there", "e") // Should return "Hllo thr"
* removeString("Hello there", "x") // Should return "Hello there"
* removeString("Hello there", "e") // Should return "Hllo thr"
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;
public String removeString(String base, String remove) {
String res = base.replaceAll("(?i)" + remove, "");
System.out.println(res);
return res;
}

/**
* Given a string, return true if the number of appearances of "is" anywhere in the string is equal
* to the number of appearances of "not" anywhere in the string (case sensitive)
*
* <p>
* example : containsEqualNumberOfIsAndNot("This is not") // Should return false
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
public Boolean containsEqualNumberOfIsAndNot(String input) {
ArrayList<String> isArrList = new ArrayList<>();
ArrayList<String> notArrList = new ArrayList<>();
boolean isEqual = false;
String is = "is";
String not = "not";

for (int i = 0; i <= input.length() - 1; i++) {
if (input.regionMatches(true, i, is, 0, is.length())) {
// System.out.println("found is");
isArrList.add("added");
}
if (input.regionMatches(true, i, not, 0, not.length())) {
// System.out.println("found not");
notArrList.add("added");
}
}
// System.out.println("length of 'is' list= " + isArrList.size());
// System.out.println("length of 'not' list= " + notArrList.size());
if (isArrList.size() == notArrList.size()) {
isEqual = true;
}
return isEqual;
}


/**
* We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right.
* Return true if all the g's in the given string are happy.
* example : gHappy("xxggxx") // Should return true
* gHappy("xxgxx") // Should return false
* gHappy("xxggyygxx") // Should return false
* gHappy("xxgxx") // Should return false
* gHappy("xxggyygxx") // Should return true
*/
public Boolean gIsHappy(String input){
return null;
public Boolean gIsHappy(String input) {
boolean outcome = false;
String gg = "gg";
for (int i = 0; i <= input.length(); i++) {
if (input.regionMatches(true, i, gg, 0, gg.length())) {
outcome = true;
}
}
return outcome;
}


/**
* We'll say that a "triple" in a string is a char appearing three times in a row.
* Return the number of triples in the given string. The triples may overlap.
* example : countTriple("abcXXXabc") // Should return 1
* countTriple("xxxabyyyycd") // Should return 3
* countTriple("a") // Should return 0
* countTriple("xxxabyyyycd") // Should return 3
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
public Integer countTriple(String input) {
int len = input.length();
int count = 0;

for (int i = 0; i < len -2; i++) {
if ((i < len) &&
input.charAt(i) == input.charAt(i + 1) &&
input.charAt(i) == input.charAt(i +2)) {
count++;
}
}
return count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void setup(){
public void countYZTest1(){
String input = "fez day";
Integer expected = 2;
Integer actual = stringsAndThings.countYZ(input);
Integer actual = Integer.valueOf(stringsAndThings.countYZ(input));
Assert.assertEquals(expected, actual);
}

Expand Down
Binary file added target/classes/io/zipcoder/StringsAndThings.class
Binary file not shown.
5 changes: 5 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Generated by Maven
#Mon Jun 27 10:41:08 EDT 2022
artifactId=strings-and-things
groupId=com.github.zipcodewilmington
version=1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/myah/Dev/stringsandthings.maven/src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/Users/myah/Dev/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/GIsHappyTest.java
/Users/myah/Dev/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/RemoveStringTest.java
/Users/myah/Dev/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/ContainsEqualNumberOfIsAndNotTest.java
/Users/myah/Dev/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/CountYZTest.java
/Users/myah/Dev/stringsandthings.maven/src/test/java/io/zipcoder/stringsandthings/CountTripleTest.java
Binary file added target/strings-and-things-1.0.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="3" failures="0" name="io.zipcoder.stringsandthings.ContainsEqualNumberOfIsAndNotTest" time="0" errors="3" skipped="0">
<properties>
<property name="idea.version" value="2022.1.3"/>
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
<property name="java.vm.version" value="18.0.1.1+2-6"/>
<property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home/lib"/>
<property name="maven.multiModuleProjectDirectory" value="/Users/myah/Dev/stringsandthings.maven"/>
<property name="java.vm.vendor" value="Oracle Corporation"/>
<property name="java.vendor.url" value="https://java.oracle.com/"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="path.separator" value=":"/>
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
<property name="user.country" value="US"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/Users/myah/Dev/stringsandthings.maven"/>
<property name="java.vm.compressedOopsMode" value="Zero based"/>
<property name="java.runtime.version" value="18.0.1.1+2-6"/>
<property name="os.arch" value="x86_64"/>
<property name="java.io.tmpdir" value="/var/folders/t8/_7shrwb51fv0pd4t1klkpbw00000gp/T/"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Mac OS X"/>
<property name="maven.ext.class.path" value="/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven-event-listener.jar"/>
<property name="classworlds.conf" value="/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/Users/myah/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/>
<property name="maven.conf" value="/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/conf"/>
<property name="jdk.debug" value="release"/>
<property name="java.class.version" value="62.0"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="maven.test.failure.ignore" value="true"/>
<property name="os.version" value="12.2.1"/>
<property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="user.home" value="/Users/myah"/>
<property name="user.timezone" value="America/New_York"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="18"/>
<property name="user.name" value="myah"/>
<property name="java.class.path" value="/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds.license:/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.6.0.jar"/>
<property name="java.vm.specification.version" value="18"/>
<property name="sun.arch.data.model" value="64"/>
<property name="sun.java.command" value="org.codehaus.classworlds.Launcher -Didea.version=2022.1.3 package -Dmaven.test.failure.ignore=true"/>
<property name="java.home" value="/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home"/>
<property name="apple.awt.application.name" value="Launcher"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="java.version" value="18.0.1.1"/>
<property name="native.encoding" value="UTF-8"/>
<property name="java.vendor" value="Oracle Corporation"/>
<property name="maven.home" value="/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3"/>
<property name="file.separator" value="/"/>
<property name="java.version.date" value="2022-04-22"/>
<property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/>
<property name="sun.io.unicode.encoding" value="UnicodeBig"/>
<property name="sun.cpu.endian" value="little"/>
<property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
</properties>
<testcase classname="io.zipcoder.stringsandthings.ContainsEqualNumberOfIsAndNotTest" name="equalIsNotTest1" time="0">
<error message="Cannot invoke &quot;java.lang.Boolean.booleanValue()&quot; because &quot;actual&quot; is null" type="java.lang.NullPointerException">java.lang.NullPointerException: Cannot invoke &quot;java.lang.Boolean.booleanValue()&quot; because &quot;actual&quot; is null
at io.zipcoder.stringsandthings.ContainsEqualNumberOfIsAndNotTest.equalIsNotTest1(ContainsEqualNumberOfIsAndNotTest.java:23)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
</error>
</testcase>
<testcase classname="io.zipcoder.stringsandthings.ContainsEqualNumberOfIsAndNotTest" name="equalIsNotTest2" time="0">
<error message="Cannot invoke &quot;java.lang.Boolean.booleanValue()&quot; because &quot;actual&quot; is null" type="java.lang.NullPointerException">java.lang.NullPointerException: Cannot invoke &quot;java.lang.Boolean.booleanValue()&quot; because &quot;actual&quot; is null
at io.zipcoder.stringsandthings.ContainsEqualNumberOfIsAndNotTest.equalIsNotTest2(ContainsEqualNumberOfIsAndNotTest.java:29)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
</error>
</testcase>
<testcase classname="io.zipcoder.stringsandthings.ContainsEqualNumberOfIsAndNotTest" name="equalIsNotTest3" time="0">
<error message="Cannot invoke &quot;java.lang.Boolean.booleanValue()&quot; because &quot;actual&quot; is null" type="java.lang.NullPointerException">java.lang.NullPointerException: Cannot invoke &quot;java.lang.Boolean.booleanValue()&quot; because &quot;actual&quot; is null
at io.zipcoder.stringsandthings.ContainsEqualNumberOfIsAndNotTest.equalIsNotTest3(ContainsEqualNumberOfIsAndNotTest.java:35)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
</error>
</testcase>
</testsuite>
Loading