tests: add tests of Mode (#5104)

This commit is contained in:
Piotr Idzik
2024-04-26 08:40:01 +02:00
committed by GitHub
parent 7a42f68b66
commit 6de154d218
2 changed files with 24 additions and 11 deletions

View File

@ -0,0 +1,21 @@
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
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 ModeTest {
@ParameterizedTest
@MethodSource("tcStream")
void basicTest(final int[] expected, final int[] numbers) {
assertArrayEquals(expected, Mode.mode(numbers));
}
private static Stream<Arguments> tcStream() {
return Stream.of(Arguments.of(null, new int[] {}), Arguments.of(new int[] {5}, new int[] {5}), Arguments.of(new int[] {1, 2, 3, 4, 5}, new int[] {1, 2, 3, 4, 5}), Arguments.of(new int[] {1, 2, 3, 4, 5}, new int[] {5, 4, 3, 2, 1}),
Arguments.of(new int[] {7}, new int[] {7, 9, 9, 4, 5, 6, 7, 7, 8}), Arguments.of(new int[] {7, 9}, new int[] {7, 9, 9, 4, 5, 6, 7, 7, 9}));
}
}