mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
Add More Tests (#4148)
This commit is contained in:

committed by
GitHub

parent
f35e9a7d81
commit
7779c18ef6
@ -7,18 +7,9 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class Median {
|
||||
|
||||
public static void main(String[] args) {
|
||||
assert median(new int[] { 0 }) == 0;
|
||||
assert median(new int[] { 1, 2 }) == 1.5;
|
||||
assert median(new int[] { 4, 1, 3, 2 }) == 2.5;
|
||||
assert median(new int[] { 1, 3, 3, 6, 7, 8, 9 }) == 6;
|
||||
assert median(new int[] { 1, 2, 3, 4, 5, 6, 8, 9 }) == 4.5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate average median
|
||||
*
|
||||
* @param values number series
|
||||
* @param values sorted numbers to find median of
|
||||
* @return median of given {@code values}
|
||||
*/
|
||||
public static double median(int[] values) {
|
||||
|
Reference in New Issue
Block a user