|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 4 |
|
5 | 5 | import org.junit.jupiter.params.ParameterizedTest;
|
6 |
| -import org.junit.jupiter.params.provider.CsvSource; |
| 6 | +import org.junit.jupiter.params.provider.Arguments; |
| 7 | +import org.junit.jupiter.params.provider.MethodSource; |
| 8 | + |
| 9 | +import java.util.stream.Stream; |
7 | 10 |
|
8 | 11 | public class AnagramsTest {
|
| 12 | + |
| 13 | + private static Stream<Arguments> anagramTestData() { |
| 14 | + return Stream.of(Arguments.of("late", "tale", true), Arguments.of("late", "teal", true), Arguments.of("listen", "silent", true), Arguments.of("hello", "olelh", true), Arguments.of("hello", "world", false), Arguments.of("deal", "lead", true), Arguments.of("binary", "brainy", true), Arguments.of("adobe", "abode", true), Arguments.of("cat", "act", true), Arguments.of("cat", "cut", false)); |
| 15 | + } |
| 16 | + |
| 17 | + @ParameterizedTest |
| 18 | + @MethodSource("anagramTestData") |
| 19 | + void testApproach1(String s, String t, boolean expected) { |
| 20 | + assertEquals(expected, Anagrams.approach1(s, t)); |
| 21 | + } |
| 22 | + |
| 23 | + @ParameterizedTest |
| 24 | + @MethodSource("anagramTestData") |
| 25 | + void testApproach2(String s, String t, boolean expected) { |
| 26 | + assertEquals(expected, Anagrams.approach2(s, t)); |
| 27 | + } |
| 28 | + |
| 29 | + @ParameterizedTest |
| 30 | + @MethodSource("anagramTestData") |
| 31 | + void testApproach3(String s, String t, boolean expected) { |
| 32 | + assertEquals(expected, Anagrams.approach3(s, t)); |
| 33 | + } |
| 34 | + |
| 35 | + @ParameterizedTest |
| 36 | + @MethodSource("anagramTestData") |
| 37 | + void testApproach4(String s, String t, boolean expected) { |
| 38 | + assertEquals(expected, Anagrams.approach4(s, t)); |
| 39 | + } |
| 40 | + |
9 | 41 | @ParameterizedTest
|
10 |
| - @CsvSource({"late, tale, true", "late, teal, true", "listen, silent, true", "hello, olelh, true", "hello, world, false", "deal, lead, true", "binary, brainy, true", "adobe, abode, true", "cat, act, true", "cat, cut, false"}) |
11 |
| - void testApproach1(String input1, String input2, boolean expected) { |
12 |
| - assertEquals(Anagrams.approach1(input1, input2), expected); |
13 |
| - assertEquals(Anagrams.approach2(input1, input2), expected); |
14 |
| - assertEquals(Anagrams.approach3(input1, input2), expected); |
15 |
| - assertEquals(Anagrams.approach4(input1, input2), expected); |
16 |
| - assertEquals(Anagrams.approach5(input1, input2), expected); |
| 42 | + @MethodSource("anagramTestData") |
| 43 | + void testApproach5(String s, String t, boolean expected) { |
| 44 | + assertEquals(expected, Anagrams.approach5(s, t)); |
17 | 45 | }
|
18 | 46 | }
|
0 commit comments