/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/java/com/thealgorithms/stacks/CelebrityFinderTest.java
41 строка
2 KB
Hardik Pawar
feat: Add `CelebrityFinder` new algorithm with Junit tests (#5756)
15 окт 2024, 11:48
Не верифицирован
15 окт 2024, 11:48
adf21ab
Код
Авторство
О чём код?
package com.thealgorithms.stacks; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; public class CelebrityFinderTest { @ParameterizedTest @MethodSource("providePartyMatrices") public void testCelebrityFinder(int[][] party, int expected) { assertEquals(expected, CelebrityFinder.findCelebrity(party)); } private static Stream<Arguments> providePartyMatrices() { return Stream.of( // Test case 1: Celebrity exists Arguments.of(new int[][] {{0, 1, 1}, {0, 0, 1}, {0, 0, 0}}, 2), // Test case 2: No celebrity Arguments.of(new int[][] {{0, 1, 0}, {1, 0, 1}, {1, 1, 0}}, -1), // Test case 3: Everyone knows each other, no celebrity Arguments.of(new int[][] {{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}, -1), // Test case 4: Single person, they are trivially a celebrity Arguments.of(new int[][] {{0}}, 0), // Test case 5: All know the last person, and they know no one Arguments.of(new int[][] {{0, 1, 1, 1}, {0, 0, 1, 1}, {0, 0, 0, 1}, {0, 0, 0, 0}}, 3), // Test case 6: Larger party with no celebrity Arguments.of(new int[][] {{0, 1, 1, 0}, {1, 0, 0, 1}, {0, 1, 0, 1}, {1, 1, 1, 0}}, -1), // Test case 7: Celebrity at the start of the matrix Arguments.of(new int[][] {{0, 0, 0}, {1, 0, 1}, {1, 1, 0}}, 0)); } }