-
-
Notifications
You must be signed in to change notification settings - Fork 692
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
isogram : add to track #311
Changes from 9 commits
9164a08
d2f7e16
a7d8b4a
1719235
9dd8b74
39e6e5a
8c05636
d99dd40
4726b05
b3dda65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apply plugin: "java" | ||
apply plugin: "eclipse" | ||
apply plugin: "idea" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testCompile "junit:junit:4.12" | ||
} | ||
test { | ||
testLogging { | ||
exceptionFormat = 'full' | ||
events = ["passed", "failed", "skipped"] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package exemple; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import static java.util.Arrays.stream; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
public class Isogram { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking that the semantics are very close on this class, but not quite right. Think of it this way: what is the purpose of this class? What do the methods do? What if, for example: IsogramChecker isogramChecker = new IsogramChecker();
String word = "isogram";
boolean result = isogramChecker.isIsogram(word); |
||
|
||
private String word; | ||
|
||
public Isogram(String word){ | ||
this.word = word; | ||
} | ||
|
||
public boolean isogramChecker(){ | ||
|
||
Set<Character> charSet = new HashSet<>(); | ||
|
||
String[] words = this.word.split(" "); | ||
String newWord = concat(words); | ||
|
||
words = newWord.split("-"); | ||
newWord = concat(words).toLowerCase(); | ||
|
||
for(int i = 0; i < newWord.length(); i++){ | ||
charSet.add(newWord.charAt(i)); | ||
} | ||
|
||
return charSet.size() == newWord.length(); | ||
} | ||
|
||
private String concat(String[] words){ | ||
return stream(words).collect(joining()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package test; | ||
|
||
import static org.junit.Assert.*; | ||
import org.junit.Test; | ||
import exemple.Isogram; | ||
|
||
public class IsogramTest { | ||
|
||
@Test | ||
public void testIsogram() { | ||
Isogram iso = new Isogram("duplicates"); | ||
assertTrue(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll want to annotate all tests except the first one with |
||
public void testNotIsogram() { | ||
Isogram iso = new Isogram("eleven"); | ||
assertFalse(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testMediumLongIsogram() { | ||
Isogram iso = new Isogram("subdermatoglyphic"); | ||
assertTrue(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testCaseInsensitive() { | ||
Isogram iso = new Isogram("Alphabet"); | ||
assertFalse(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testIsogramWithHyphen() { | ||
Isogram iso = new Isogram("thumbscrew-japingly"); | ||
assertTrue(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testIgnoresMultipleHyphens() { | ||
Isogram iso = new Isogram("Hjelmqvist-Gryb-Zock-Pfund-Wax"); | ||
assertTrue(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testWorksWithGermanLetters() { | ||
Isogram iso = new Isogram("Heizölrückstoßabdämpfung"); | ||
assertTrue(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testIgnoresSpaces() { | ||
Isogram iso = new Isogram("the quick brown fox"); | ||
assertFalse(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testIgnoresSpaces2() { | ||
Isogram iso = new Isogram("Emily Jung Schwartzkopf"); | ||
assertTrue(iso.isogramChecker()); | ||
} | ||
|
||
@Test | ||
public void testDuplicateAccentedLetters() { | ||
Isogram iso = new Isogram("éléphant"); | ||
assertFalse(iso.isogramChecker()); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a typo here, should be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, french mistake!