|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
4 | 4 |
|
5 |
| -import org.junit.jupiter.api.Test; |
| 5 | +import java.util.stream.Stream; |
| 6 | +import org.junit.jupiter.params.ParameterizedTest; |
| 7 | +import org.junit.jupiter.params.provider.Arguments; |
| 8 | +import org.junit.jupiter.params.provider.MethodSource; |
6 | 9 |
|
7 | 10 | public class CelebrityFinderTest {
|
8 | 11 |
|
9 |
| - @Test |
10 |
| - public void testCelebrityExists() { |
11 |
| - int[][] party = {{0, 1, 1}, {0, 0, 1}, {0, 0, 0}}; |
12 |
| - assertEquals(2, CelebrityFinder.findCelebrity(party)); |
| 12 | + @ParameterizedTest |
| 13 | + @MethodSource("providePartyMatrices") |
| 14 | + public void testCelebrityFinder(int[][] party, int expected) { |
| 15 | + assertEquals(expected, CelebrityFinder.findCelebrity(party)); |
13 | 16 | }
|
14 | 17 |
|
15 |
| - @Test |
16 |
| - public void testNoCelebrity() { |
17 |
| - int[][] party = {{0, 1, 0}, {1, 0, 1}, {1, 1, 0}}; |
18 |
| - assertEquals(-1, CelebrityFinder.findCelebrity(party)); |
| 18 | + private static Stream<Arguments> providePartyMatrices() { |
| 19 | + return Stream.of( |
| 20 | + // Test case 1: Celebrity exists |
| 21 | + Arguments.of(new int[][] {{0, 1, 1}, {0, 0, 1}, {0, 0, 0}}, 2), |
| 22 | + |
| 23 | + // Test case 2: No celebrity |
| 24 | + Arguments.of(new int[][] {{0, 1, 0}, {1, 0, 1}, {1, 1, 0}}, -1), |
| 25 | + |
| 26 | + // Test case 3: Everyone knows each other, no celebrity |
| 27 | + Arguments.of(new int[][] {{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}, -1), |
| 28 | + |
| 29 | + // Test case 4: Single person, they are trivially a celebrity |
| 30 | + Arguments.of(new int[][] {{0}}, 0), |
| 31 | + |
| 32 | + // Test case 5: All know the last person, and they know no one |
| 33 | + Arguments.of(new int[][] {{0, 1, 1, 1}, {0, 0, 1, 1}, {0, 0, 0, 1}, {0, 0, 0, 0}}, 3), |
| 34 | + |
| 35 | + // Test case 6: Larger party with no celebrity |
| 36 | + Arguments.of(new int[][] {{0, 1, 1, 0}, {1, 0, 0, 1}, {0, 1, 0, 1}, {1, 1, 1, 0}}, -1), |
| 37 | + |
| 38 | + // Test case 7: Celebrity at the start of the matrix |
| 39 | + Arguments.of(new int[][] {{0, 0, 0}, {1, 0, 1}, {1, 1, 0}}, 0)); |
19 | 40 | }
|
20 | 41 | }
|
0 commit comments