forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighorderTest.java
More file actions
36 lines (26 loc) · 1.12 KB
/
Copy pathHighorderTest.java
File metadata and controls
36 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package modern.challenge;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import static modern.challenge.Main.reduceStrings;
import static modern.challenge.Main.replace;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class HighorderTest {
@Test
public void testReplacer() throws Exception {
List<String> names = Arrays.asList("Ann a 15", "Mir el 28", "D oru 33");
List<String> resultWs = replace(names, (String s) -> s.replaceAll("\\s", ""));
List<String> resultNr = replace(names, (String s) -> s.replaceAll("\\d", ""));
assertEquals(Arrays.asList("Anna15", "Mirel28", "Doru33"), resultWs);
assertEquals(Arrays.asList("Ann a ", "Mir el ", "D oru "), resultNr);
}
@Test
@SuppressWarnings("unchecked")
public void testReduceStrings() throws Exception {
Function<String, String> f1 = (String s) -> s.toUpperCase();
Function<String, String> f2 = (String s) -> s.concat(" DONE");
Function<String, String> f = reduceStrings(f1, f2);
assertEquals("TEST DONE", f.apply("test"));
}
}