Utils { public static double median(ArrayList<Double> arrList) { ArrayList<Double> lst = new ArrayList<>(arrList); Collections.sort(lst); int len = lst.size(); if (len == 0) { return Double.NaN; } if (len % 2 == 1) { return lst.get(len / 2); } else { return 0.5 * (lst.get(len / 2) + lst.get(len / 2 - 1)); } }  static double median(ArrayList<Double> arrList); static double mean(double[] x); static double[] interp(double[] x, double[] xp, double[] yp); static double stdev(double[] a); static double[] extract(int[] indicator, int value, double[] arr); static String array2string(double[] a, String format); static int argmax(double[] a); static int argmin(double[] a); static double findBestShift(double[] laserT, double[] touchT, double[] touchY);  }
@Test public void testMedian_singleNumber() { ArrayList<Double> arr = new ArrayList<>(); arr.add(0d); assertThat(Utils.median(arr), is(0d)); }
@Test public void testMedian_evenSize() { ArrayList<Double> arr = new ArrayList<>(); arr.add(1d); arr.add(2d); arr.add(3d); arr.add(4d); assertThat(Utils.median(arr), is(2.5d)); }
@Test public void testMedian_oddSize() { ArrayList<Double> arr = new ArrayList<>(); arr.add(1d); arr.add(2d); arr.add(3d); arr.add(4d); arr.add(5d); assertThat(Utils.median(arr), is(3d)); }