Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathAnagramsTest.java
More file actions
Latest commit
49 lines (39 loc) · 2.31 KB
/
Copy pathAnagramsTest.java
File metadata and controls
49 lines (39 loc) · 2.31 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
37
38
39
40
41
42
43
44
45
46
47
48
49
packagecom.thealgorithms.strings;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.MethodSource;
publicclassAnagramsTest {
recordAnagramTestCase(Stringinput1, Stringinput2, booleanexpected) {
}
privatestaticStream<AnagramTestCase> anagramTestData() {
returnStream.of(newAnagramTestCase("late", "tale", true), newAnagramTestCase("late", "teal", true), newAnagramTestCase("listen", "silent", true), newAnagramTestCase("hello", "olelh", true), newAnagramTestCase("hello", "world", false), newAnagramTestCase("deal", "lead", true),
newAnagramTestCase("binary", "brainy", true), newAnagramTestCase("adobe", "abode", true), newAnagramTestCase("cat", "act", true), newAnagramTestCase("cat", "cut", false), newAnagramTestCase("Listen", "Silent", true), newAnagramTestCase("Dormitory", "DirtyRoom", true),
newAnagramTestCase("Schoolmaster", "TheClassroom", true), newAnagramTestCase("Astronomer", "MoonStarer", true), newAnagramTestCase("Conversation", "VoicesRantOn", true));
}
@ParameterizedTest
@MethodSource("anagramTestData")
voidtestApproach1(AnagramTestCasetestCase) {
assertEquals(testCase.expected(), Anagrams.areAnagramsBySorting(testCase.input1(), testCase.input2()));
}
@ParameterizedTest
@MethodSource("anagramTestData")
voidtestApproach2(AnagramTestCasetestCase) {
assertEquals(testCase.expected(), Anagrams.areAnagramsByCountingChars(testCase.input1(), testCase.input2()));
}
@ParameterizedTest
@MethodSource("anagramTestData")
voidtestApproach3(AnagramTestCasetestCase) {
assertEquals(testCase.expected(), Anagrams.areAnagramsByCountingCharsSingleArray(testCase.input1(), testCase.input2()));
}
@ParameterizedTest
@MethodSource("anagramTestData")
voidtestApproach4(AnagramTestCasetestCase) {
assertEquals(testCase.expected(), Anagrams.areAnagramsUsingHashMap(testCase.input1(), testCase.input2()));
}
@ParameterizedTest
@MethodSource("anagramTestData")
voidtestApproach5(AnagramTestCasetestCase) {
assertEquals(testCase.expected(), Anagrams.areAnagramsBySingleFreqArray(testCase.input1(), testCase.input2()));
}
}