瀏覽代碼

parallel-letter-frequency: remove characters with accents / diacritics (#1109)

* parallel-letter-frequency: remove characters with accents / diacritics

* parallel-letter-frequency: update README with stretch goal

* parallel-letter-frequency: fix readme
Sam Warner 8 年之前
父節點
當前提交
27acf8eb1d

+ 2
- 0
exercises/parallel-letter-frequency/.meta/HINTS.md 查看文件

1
 Single-threaded (non-concurrent) solutions can pass all tests [but the last.](https://www.youtube.com/watch?v=mJZZNHekEQw)  Your solution will be tested for concurrency by submitting it as a [Runnable](https://docs.oracle.com/javase/7/docs/api/java/lang/Runnable.html) to an [ExecutorService.](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html) Your solution must leverage multiple [Threads](https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html) to pass the final test.
1
 Single-threaded (non-concurrent) solutions can pass all tests [but the last.](https://www.youtube.com/watch?v=mJZZNHekEQw)  Your solution will be tested for concurrency by submitting it as a [Runnable](https://docs.oracle.com/javase/7/docs/api/java/lang/Runnable.html) to an [ExecutorService.](https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html) Your solution must leverage multiple [Threads](https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html) to pass the final test.
2
 
2
 
3
 Java documentation on [parallel streams](https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html) may provide some help.
3
 Java documentation on [parallel streams](https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html) may provide some help.
4
+
5
+As a stretch goal, consider if your implementation will work for characters with [diacritics or accents](https://en.wikipedia.org/wiki/Diacritic). For example, such solutions should not consider e and ë the same character. An example text for this case is [Wilhelmus](https://en.wikipedia.org/wiki/Wilhelmus), the Dutch national anthem.

+ 1
- 0
exercises/parallel-letter-frequency/README.md 查看文件

13
 
13
 
14
 Java documentation on [parallel streams](https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html) may provide some help.
14
 Java documentation on [parallel streams](https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html) may provide some help.
15
 
15
 
16
+As a stretch goal, consider if your implementation will work for characters with [diacritics or accents](https://en.wikipedia.org/wiki/Diacritic). For example, such solutions should not consider e and ë the same character. An example text for this case is [Wilhelmus](https://en.wikipedia.org/wiki/Wilhelmus), the Dutch national anthem.
16
 
17
 
17
 # Running the tests
18
 # Running the tests
18
 
19
 

+ 1
- 38
exercises/parallel-letter-frequency/src/test/java/ParallelLetterFrequencyTest.java 查看文件

8
 
8
 
9
 public class ParallelLetterFrequencyTest {
9
 public class ParallelLetterFrequencyTest {
10
 
10
 
11
-    // Poem by Friedrich Schiller. The corresponding music is the European Anthem.
12
-    private String OdeAnDieFreude =
13
-            "Freude schöner Götterfunken\n" +
14
-                    "Tochter aus Elysium,\n" +
15
-                    "Wir betreten feuertrunken,\n" +
16
-                    "Himmlische, dein Heiligtum!\n" +
17
-                    "Deine Zauber binden wieder\n" +
18
-                    "Was die Mode streng geteilt;\n" +
19
-                    "Alle Menschen werden Brüder,\n" +
20
-                    "Wo dein sanfter Flügel weilt.";
21
-
22
-    // Dutch national anthem
23
-    private String Wilhelmus =
24
-            "Wilhelmus van Nassouwe\n" +
25
-                    "ben ik, van Duitsen bloed,\n" +
26
-                    "den vaderland getrouwe\n" +
27
-                    "blijf ik tot in den dood.\n" +
28
-                    "Een Prinse van Oranje\n" +
29
-                    "ben ik, vrij, onverveerd,\n" +
30
-                    "den Koning van Hispanje\n" +
31
-                    "heb ik altijd geëerd.";
32
-
33
     // American national anthem
11
     // American national anthem
34
     private String StarSpangledBanner =
12
     private String StarSpangledBanner =
35
             "O say can you see by the dawn's early light,\n" +
13
             "O say can you see by the dawn's early light,\n" +
118
     @Ignore("Remove to run test")
96
     @Ignore("Remove to run test")
119
     @Test
97
     @Test
120
     public void punctuationDoesntCount() {
98
     public void punctuationDoesntCount() {
121
-        ParallelLetterFrequency p = new ParallelLetterFrequency(OdeAnDieFreude);
99
+        ParallelLetterFrequency p = new ParallelLetterFrequency(StarSpangledBanner);
122
 
100
 
123
         assertFalse(p.letterCounts().containsKey((int) ','));
101
         assertFalse(p.letterCounts().containsKey((int) ','));
124
     }
102
     }
133
 
111
 
134
     @Ignore("Remove to run test")
112
     @Ignore("Remove to run test")
135
     @Test
113
     @Test
136
-    public void allThreeAnthemsTogetherProduceCorrectCounts() {
137
-        StringBuilder b = new StringBuilder();
138
-        b.append(OdeAnDieFreude);
139
-        b.append(Wilhelmus);
140
-        b.append(StarSpangledBanner);
141
-
142
-        ParallelLetterFrequency p = new ParallelLetterFrequency(b.toString());
143
-
144
-        assertEquals(new Integer(49), p.letterCounts().get((int) 'a'));
145
-        assertEquals(new Integer(56), p.letterCounts().get((int) 't'));
146
-        assertEquals(new Integer(2), p.letterCounts().get((int) 'ü'));
147
-    }
148
-
149
-    @Ignore("Remove to run test")
150
-    @Test
151
     public void multipleThreadsGetUsed()
114
     public void multipleThreadsGetUsed()
152
             throws InterruptedException, ExecutionException {
115
             throws InterruptedException, ExecutionException {
153
 
116