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

isogram : add to track #311

Merged
merged 10 commits into from
Mar 17, 2017
Empty file added .Rhistory
Empty file.
7 changes: 7 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"language": "Java",
"repository": "https://github.com/exercism/xjava",
"active": true,

"exercises": [
{
"slug": "hello-world",
Expand Down Expand Up @@ -313,6 +314,11 @@
"slug": "ocr-numbers",
"difficulty": 1,
"topics": []
},
{
"slug": "isogram",
"difficulty": 1,
"topics": []
}
],
"deprecated": [
Expand All @@ -335,3 +341,4 @@
"say"
]
}

17 changes: 17 additions & 0 deletions exercises/isogram/build.gradle
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"]
}
}
37 changes: 37 additions & 0 deletions exercises/isogram/src/example/java/Isogram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package exemple;
Copy link
Contributor

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:

package example;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, french mistake!


import java.util.HashSet;
import java.util.Set;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;

public class Isogram {
Copy link
Contributor

Choose a reason for hiding this comment

The 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());
}

}
Empty file.
69 changes: 69 additions & 0 deletions exercises/isogram/src/test/java/IsogramTest.java
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to annotate all tests except the first one with @Ignore, so the users can explore their solution using each test as a goalpost.

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());
}

}
1 change: 1 addition & 0 deletions exercises/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include 'grade-school'
include 'hamming'
include 'hexadecimal'
include 'hello-world'
include 'isogram'
include 'largest-series-product'
include 'linked-list'
include 'list-ops'
Expand Down