/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/test/java/com/thealgorithms/others/BoyerMooreTest.java
30 строк
1 KB
Alex Klymenko
refactor: `BoyerMoore` (#5395)
26 авг 2024, 10:33
Не верифицирован
26 авг 2024, 10:33
35f23d2
Код
Авторство
О чём код?
package com.thealgorithms.others; import java.util.stream.Stream; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; public class BoyerMooreTest { @ParameterizedTest @MethodSource("inputStreamWithExistingMajority") void checkWhenMajorityExists(int expected, int[] input) { Assertions.assertEquals(expected, BoyerMoore.findMajorityElement(input).get()); } private static Stream<Arguments> inputStreamWithExistingMajority() { return Stream.of(Arguments.of(5, new int[] {5, 5, 5, 2}), Arguments.of(10, new int[] {10, 10, 20}), Arguments.of(10, new int[] {10, 20, 10}), Arguments.of(10, new int[] {20, 10, 10}), Arguments.of(4, new int[] {1, 4, 2, 4, 4, 5, 4}), Arguments.of(-1, new int[] {-1})); } @ParameterizedTest @MethodSource("inputStreamWithoutMajority") void checkWhenMajorityExists(int[] input) { Assertions.assertFalse(BoyerMoore.findMajorityElement(input).isPresent()); } private static Stream<Arguments> inputStreamWithoutMajority() { return Stream.of(Arguments.of(new int[] {10, 10, 20, 20, 30, 30}), Arguments.of(new int[] {10, 20, 30, 40, 50}), Arguments.of(new int[] {1, 2}), Arguments.of(new int[] {})); } }