From 7a52227bbd4d764db4ceba8213cacd99aab45a31 Mon Sep 17 00:00:00 2001 From: ptuor Date: Sat, 10 Oct 2020 14:27:35 +0200 Subject: [PATCH 1/2] Add implementation for isogram checker Checks if phrase is isogram or not. Whitespaces and hyphens are ignored and will not count as repeaded char. --- .../src/main/java/IsogramChecker.java | 13 ++++++++++++- .../src/test/java/IsogramCheckerTest.java | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clean-code-challanges/src/main/java/IsogramChecker.java b/clean-code-challanges/src/main/java/IsogramChecker.java index 00d4c74..0ea8a5b 100644 --- a/clean-code-challanges/src/main/java/IsogramChecker.java +++ b/clean-code-challanges/src/main/java/IsogramChecker.java @@ -1,3 +1,5 @@ +import java.util.stream.Collectors; + /** * Determine if a word or phrase is an isogram. * @@ -16,7 +18,16 @@ class IsogramChecker { boolean isIsogram(String phrase) { - throw new UnsupportedOperationException("Delete this statement and write your own implementation."); + final String whiteSpacesAndHyphens = "[\\s\\-]"; + + String cleanPhrase = phrase.replaceAll(whiteSpacesAndHyphens, "").toLowerCase(); + + int numberOfUniqueCharacters = cleanPhrase.chars() + .mapToObj(o -> (char)o) + .collect(Collectors.toSet()) + .size(); + + return cleanPhrase.length() == numberOfUniqueCharacters; } } diff --git a/clean-code-challanges/src/test/java/IsogramCheckerTest.java b/clean-code-challanges/src/test/java/IsogramCheckerTest.java index e6808f9..188d4fd 100644 --- a/clean-code-challanges/src/test/java/IsogramCheckerTest.java +++ b/clean-code-challanges/src/test/java/IsogramCheckerTest.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -@Ignore + public class IsogramCheckerTest { @Test From 45d77889ec43b178dbad15663067a35909325f8f Mon Sep 17 00:00:00 2001 From: ptuor Date: Sat, 10 Oct 2020 14:36:19 +0200 Subject: [PATCH 2/2] ignore PigLatinTranslator Tests --- .../src/test/java/PigLatinTranslatorTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clean-code-challanges/src/test/java/PigLatinTranslatorTest.java b/clean-code-challanges/src/test/java/PigLatinTranslatorTest.java index c26cdcd..ff760f5 100644 --- a/clean-code-challanges/src/test/java/PigLatinTranslatorTest.java +++ b/clean-code-challanges/src/test/java/PigLatinTranslatorTest.java @@ -1,3 +1,4 @@ +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -6,8 +7,8 @@ import java.util.Collection; import static org.junit.Assert.assertEquals; - @RunWith(Parameterized.class) +@Ignore public class PigLatinTranslatorTest { private String englishPhrase;