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

@ -1,7 +1,6 @@
package com.thealgorithms.maths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@ -11,15 +10,8 @@ import java.util.HashMap;
* The mode of an array of numbers is the most frequently occurring number in the array,
* or the most frequently occurring numbers if there are multiple numbers with the same frequency
*/
public class Mode {
public static void main(String[] args) {
/* Test array of integers */
assert (mode(new int[] {})) == null;
assert Arrays.equals(mode(new int[] {5}), new int[] {5});
assert Arrays.equals(mode(new int[] {1, 2, 3, 4, 5}), new int[] {1, 2, 3, 4, 5});
assert Arrays.equals(mode(new int[] {7, 9, 9, 4, 5, 6, 7, 7, 8}), new int[] {7});
assert Arrays.equals(mode(new int[] {7, 9, 9, 4, 5, 6, 7, 7, 9}), new int[] {7, 9});
public final class Mode {
private Mode() {
}
/*
@ -28,7 +20,7 @@ public class Mode {
* @param numbers array of integers
* @return mode of the array
*/
public static int[] mode(int[] numbers) {
public static int[] mode(final int[] numbers) {
if (numbers.length == 0) {
return null;
}