-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathGroupAnagramsTest.java
More file actions
25 lines (19 loc) · 881 Bytes
/
GroupAnagramsTest.java
File metadata and controls
25 lines (19 loc) · 881 Bytes
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
import org.junit.Assert;
import org.junit.Test;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class GroupAnagramsTest {
@Test
public void testGroupAnagrams() {
GroupAnagrams ga = new GroupAnagrams();
Assert.assertTrue(ga.groupAnagrams(new String[]{}).isEmpty());
List<List<String>> list0 = ga.groupAnagrams(new String[]{"eat", "tea", "tan", "ate", "nat", "bat"});
Set<Set<String>> set = new HashSet<>();
set.add(new HashSet<>(Arrays.asList("ate", "eat", "tea")));
set.add(new HashSet<>(Arrays.asList("nat", "tan")));
set.add(new HashSet<>(Collections.singletonList("bat")));
Assert.assertTrue(list0.size() == 3);
Assert.assertEquals(list0.stream().map((Function<List<String>, HashSet>) HashSet::new).collect(Collectors.toSet()), set);
}
}