From 30e40356ccc0832f9354d8bc25423272e8602e54 Mon Sep 17 00:00:00 2001 From: yuri_u Date: Wed, 19 Aug 2015 18:10:17 -0700 Subject: [PATCH 1/7] initial commit --- .classpath | 37 ++++++++++++ .project | 23 ++++++++ .settings/org.eclipse.jdt.core.prefs | 5 ++ .settings/org.eclipse.m2e.core.prefs | 4 ++ pom.xml | 6 ++ src/main/java/stringProblem/StringMethod.java | 18 ++++++ .../java/stringProblem/StringMethodTest.java | 59 +++++++++++++++++++ 7 files changed, 152 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 pom.xml create mode 100644 src/main/java/stringProblem/StringMethod.java create mode 100644 src/test/java/stringProblem/StringMethodTest.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..8a37db5 --- /dev/null +++ b/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..b260e0e --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + stringProblem + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..abec6ca --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..895f079 --- /dev/null +++ b/pom.xml @@ -0,0 +1,6 @@ + + 4.0.0 + com.iappsqainterview + stringProblem + 0.0.1-SNAPSHOT + \ No newline at end of file diff --git a/src/main/java/stringProblem/StringMethod.java b/src/main/java/stringProblem/StringMethod.java new file mode 100644 index 0000000..52f8684 --- /dev/null +++ b/src/main/java/stringProblem/StringMethod.java @@ -0,0 +1,18 @@ +package stringProblem; + +public class StringMethod { + public static String loopMethod(String word, char i) { + String newWord = ""; + for(int k = 0; k < word.length(); k++) { + if(word.charAt(k) != i) { + newWord += word.charAt(k); + } else {continue;} + } + return newWord; + } + + public static String stringFunction(String word, char i) { + String newString = word.replaceAll(i+"", ""); + return newString; + } +} diff --git a/src/test/java/stringProblem/StringMethodTest.java b/src/test/java/stringProblem/StringMethodTest.java new file mode 100644 index 0000000..ff2dd52 --- /dev/null +++ b/src/test/java/stringProblem/StringMethodTest.java @@ -0,0 +1,59 @@ +package stringProblem; + +import static org.junit.Assert.*; + +//import org.junit.BeforeClass; +import org.junit.Test; + +public class StringMethodTest { + StringMethod sm = new StringMethod(); + + @Test + public void positiveTestLooping() { + assertEquals("Assert that all instances of 'l' removed from 'Hello World!'", + "Heo Word!", sm.loopMethod("Hello World!", 'l')); + } + + @Test + public void positiveTestLooping2() { + assertEquals("Assert that all instances of 'H' removed from 'Hello World!'", + "ello World!", sm.loopMethod("Hello World!", 'H') ); + } + + @Test + public void positiveTestLooping3() { + assertNotEquals("Assert that all instances of 'l' removed from 'Hello World!'", + "Hello World!", sm.loopMethod("Hello World!", 'l')); + } + + @Test + public void positiveTestLooping4() { + assertNotEquals("Assert that all instances of 'l' removed from 'Hello World!'", + "Hello World!", sm.loopMethod("43536364", '4')); + } + + @Test + public void positiveTestLooping5() { + assertNotEquals("Assert that all instances of 'l' removed from 'Hello World!'", + "Hello World!", sm.loopMethod("", '5')); + } + + @Test + public void positiveTestStringMethod() { + assertEquals("Assert that all instances of 'l' removed from 'Hello World!'", + "Heo Word!", sm.stringFunction("Hello World!", 'l')); + } + + @Test + public void positiveTestStringMethod2() { + assertEquals("Assert that all instances of 'H' removed from 'Hello World!'", + "ello World!", sm.stringFunction("Hello World!", 'H') ); + } + + @Test + public void positiveTestStringMethod3() { + assertNotEquals("Assert that all instances of 'H' removed from 'Hello World!'", + "Hello World!", sm.stringFunction("Hello World!", 'H') ); + } +} + From 6111b4609fd5d306bf51672e76b0134e5f5255e3 Mon Sep 17 00:00:00 2001 From: ustinus Date: Wed, 19 Aug 2015 18:32:12 -0700 Subject: [PATCH 2/7] Update READ.ME --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..7058064 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# stringProblem + +Define a Java class to solve this problem:
+Given a String and a Character, remove all instances of the Character in the String + +Solve this two ways:
+1. Iterate through the String, one character at a time
+2. Find a method in the String class that can solve this in one line
+ +Write methods for each solution. + +Afterwards, write a TestNG or JUnit class for each solution which tests these methods.
+Include both positive and negative cases for validations. ++ From 836fc80ae771a97a281b55ca43ed3b0d7966c916 Mon Sep 17 00:00:00 2001 From: yuri_u Date: Mon, 24 Aug 2015 09:45:35 -0700 Subject: [PATCH 3/7] Changed String to StringBuffer --- .classpath | 10 ---------- src/main/java/stringProblem/StringMethod.java | 6 +++--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.classpath b/.classpath index 8a37db5..4e4d00b 100644 --- a/.classpath +++ b/.classpath @@ -6,22 +6,12 @@ - - - - - - - - - - diff --git a/src/main/java/stringProblem/StringMethod.java b/src/main/java/stringProblem/StringMethod.java index 52f8684..ad614fc 100644 --- a/src/main/java/stringProblem/StringMethod.java +++ b/src/main/java/stringProblem/StringMethod.java @@ -2,13 +2,13 @@ public class StringMethod { public static String loopMethod(String word, char i) { - String newWord = ""; + StringBuffer newWord = new StringBuffer(); for(int k = 0; k < word.length(); k++) { if(word.charAt(k) != i) { - newWord += word.charAt(k); + newWord.append(word.charAt(k)); } else {continue;} } - return newWord; + return newWord.toString(); } public static String stringFunction(String word, char i) { From a67b6f03170dee20a7f366799a4abb8193744ee1 Mon Sep 17 00:00:00 2001 From: ustinus Date: Tue, 25 Aug 2015 18:09:56 -0700 Subject: [PATCH 4/7] Delete .project --- .project | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .project diff --git a/.project b/.project deleted file mode 100644 index b260e0e..0000000 --- a/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - stringProblem - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - From ab258f01022701fa55f51969bd06b2f08e27577e Mon Sep 17 00:00:00 2001 From: ustinus Date: Tue, 25 Aug 2015 18:10:51 -0700 Subject: [PATCH 5/7] Delete .classpath --- .classpath | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .classpath diff --git a/.classpath b/.classpath deleted file mode 100644 index 4e4d00b..0000000 --- a/.classpath +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - From 34a11d375ece706f15919e00a1ba6d9b06623d57 Mon Sep 17 00:00:00 2001 From: ustinus Date: Tue, 25 Aug 2015 18:11:09 -0700 Subject: [PATCH 6/7] Delete org.eclipse.jdt.core.prefs --- .settings/org.eclipse.jdt.core.prefs | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .settings/org.eclipse.jdt.core.prefs diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index abec6ca..0000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.5 From 8a93d68250f23755e07a6c20fcc0158bb2c14b18 Mon Sep 17 00:00:00 2001 From: ustinus Date: Tue, 25 Aug 2015 18:11:17 -0700 Subject: [PATCH 7/7] Delete org.eclipse.m2e.core.prefs --- .settings/org.eclipse.m2e.core.prefs | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .settings/org.eclipse.m2e.core.prefs diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f..0000000 --- a/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1