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