Bladeren bron

isogram : add to track (#311)

* dibs: I will implement exercise isogram

* isogram: add to track

* isogram: add to track

* improve Isogram implementation

* Isogram: adjust API to use instance methods

* Improve Isogram implementation
Bastien FAUCHART 9 jaren geleden
bovenliggende
commit
6dd6ed60f1

+ 0
- 0
.Rhistory Bestand weergeven


+ 7
- 0
config.json Bestand weergeven

3
   "language": "Java",
3
   "language": "Java",
4
   "repository": "https://github.com/exercism/xjava",
4
   "repository": "https://github.com/exercism/xjava",
5
   "active": true,
5
   "active": true,
6
+
6
   "exercises": [
7
   "exercises": [
7
     {
8
     {
8
       "slug": "hello-world",
9
       "slug": "hello-world",
313
       "slug": "ocr-numbers",
314
       "slug": "ocr-numbers",
314
       "difficulty": 1,
315
       "difficulty": 1,
315
       "topics": []
316
       "topics": []
317
+    },
318
+    {
319
+      "slug": "isogram",
320
+      "difficulty": 1,
321
+      "topics": []
316
     }
322
     }
317
   ],
323
   ],
318
   "deprecated": [
324
   "deprecated": [
335
     "say"
341
     "say"
336
   ]
342
   ]
337
 }
343
 }
344
+

+ 17
- 0
exercises/isogram/build.gradle Bestand weergeven

1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.12"
11
+}
12
+test {
13
+  testLogging {
14
+    exceptionFormat = 'full'
15
+    events = ["passed", "failed", "skipped"]
16
+  }
17
+}

+ 34
- 0
exercises/isogram/src/example/java/IsogramChecker.java Bestand weergeven

1
+package example;
2
+
3
+import java.util.HashSet;
4
+import java.util.Set;
5
+import static java.util.Arrays.stream;
6
+import static java.util.stream.Collectors.joining;
7
+
8
+public class IsogramChecker {
9
+	
10
+	public IsogramChecker(){
11
+	}
12
+	
13
+	public boolean isIsogram(String word){
14
+		
15
+		Set<Character> charSet = new HashSet<>();
16
+		
17
+		String[] words = word.split(" ");
18
+		String newWord = concat(words);
19
+		
20
+		words = newWord.split("-");
21
+		newWord = concat(words).toLowerCase();
22
+		
23
+		for(int i = 0; i < newWord.length(); i++){
24
+			charSet.add(newWord.charAt(i));
25
+		}
26
+		
27
+		return charSet.size() == newWord.length();
28
+	}
29
+	
30
+	private String concat(String[] words){
31
+		return stream(words).collect(joining());
32
+	}
33
+	
34
+}

+ 0
- 0
exercises/isogram/src/main/java/.keep Bestand weergeven


+ 80
- 0
exercises/isogram/src/test/java/IsogramTest.java Bestand weergeven

1
+package test;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+import org.junit.Ignore;
6
+import org.junit.Test;
7
+import example.IsogramChecker;
8
+
9
+public class IsogramTest {
10
+
11
+	@Test
12
+	public void testIsogram() {
13
+		IsogramChecker iso = new IsogramChecker();
14
+		assertTrue(iso.isIsogram("duplicates"));
15
+	}
16
+	
17
+	@Ignore
18
+	@Test
19
+	public void testNotIsogram() {
20
+		IsogramChecker iso = new IsogramChecker();
21
+		assertFalse(iso.isIsogram("eleven"));
22
+	}
23
+	
24
+	@Ignore
25
+	@Test
26
+	public void testMediumLongIsogram() {
27
+		IsogramChecker iso = new IsogramChecker();
28
+		assertTrue(iso.isIsogram("subdermatoglyphic"));
29
+	}
30
+	
31
+	@Ignore
32
+	@Test
33
+	public void testCaseInsensitive() {
34
+		IsogramChecker iso = new IsogramChecker();
35
+		assertFalse(iso.isIsogram("Alphabet"));
36
+	}
37
+	
38
+	@Ignore
39
+	@Test
40
+	public void testIsogramWithHyphen() {
41
+		IsogramChecker iso = new IsogramChecker();
42
+		assertTrue(iso.isIsogram("thumbscrew-japingly"));
43
+	}
44
+	
45
+	@Ignore
46
+	@Test
47
+	public void testIgnoresMultipleHyphens() {
48
+		IsogramChecker iso = new IsogramChecker();
49
+		assertTrue(iso.isIsogram("Hjelmqvist-Gryb-Zock-Pfund-Wax"));
50
+	}
51
+	
52
+	@Ignore
53
+	@Test
54
+	public void testWorksWithGermanLetters() {
55
+		IsogramChecker iso = new IsogramChecker();
56
+		assertTrue(iso.isIsogram("Heizölrückstoßabdämpfung"));
57
+	}
58
+	
59
+	@Ignore
60
+	@Test
61
+	public void testIgnoresSpaces() {
62
+		IsogramChecker iso = new IsogramChecker();
63
+		assertFalse(iso.isIsogram("the quick brown fox"));
64
+	}
65
+	
66
+	@Ignore
67
+	@Test
68
+	public void testIgnoresSpaces2() {
69
+		IsogramChecker iso = new IsogramChecker();
70
+		assertTrue(iso.isIsogram("Emily Jung Schwartzkopf"));
71
+	}
72
+	
73
+	@Ignore
74
+	@Test
75
+	public void testDuplicateAccentedLetters() {
76
+		IsogramChecker iso = new IsogramChecker();
77
+		assertFalse(iso.isIsogram("éléphant"));
78
+	}
79
+
80
+}

+ 1
- 0
exercises/settings.gradle Bestand weergeven

23
 include 'hamming'
23
 include 'hamming'
24
 include 'hexadecimal'
24
 include 'hexadecimal'
25
 include 'hello-world'
25
 include 'hello-world'
26
+include 'isogram'
26
 include 'largest-series-product'
27
 include 'largest-series-product'
27
 include 'linked-list'
28
 include 'linked-list'
28
 include 'list-ops'
29
 include 'list-ops'