### Question:
StatisticsUtil { public static Statistics statisticsOf(CollectionNumber data) { IteratorNumber iterator = data.iterator(); if (!iterator.hasNext()) { return null; } int count = 0; double min = iterator.nextDouble(); while (Double.isNaN(min)) { if (!iterator.hasNext()) { return null; } else { min = iterator.nextDouble(); } } double max = min; double total = min; double totalSquare = min*min; count++; while (iterator.hasNext()) { double value = iterator.nextDouble(); if (!Double.isNaN(value)) { if (value > max) max = value; if (value < min) min = value; total += value; totalSquare += value*value; count++; } } double average = total/count; double stdDev = Math.sqrt(totalSquare / count - average * average); return new StatisticsImpl(Ranges.range(min, max), count, average, stdDev); }  static Statistics statisticsOf(CollectionNumber data); static Statistics statisticsOf(List<Statistics> data); static Statistics lazyStatisticsOf(CollectionNumber data);  }### Answer:
@Test public void statisticsOf1() { Statistics stats = StatisticsUtil.statisticsOf(new ArrayDouble(1.0)); assertThat(stats.getAverage(), equalTo(1.0)); assertThat(stats.getStdDev(), equalTo(0.0)); assertThat(stats.getRange().getMinimum(), equalTo(1.0)); assertThat(stats.getRange().getMaximum(), equalTo(1.0)); assertThat(stats.getCount(), equalTo(1)); }
@Test public void statisticsOf2() { Statistics stats = StatisticsUtil.statisticsOf(new ArrayDouble(1, 3, 5, -1, 7)); assertThat(stats.getAverage(), equalTo(3.0)); assertThat(stats.getStdDev(), equalTo(2.8284271247461903)); assertThat(stats.getRange().getMinimum(), equalTo(-1.0)); assertThat(stats.getRange().getMaximum(), equalTo(7.0)); assertThat(stats.getCount(), equalTo(5)); }
@Test public void statisticsOf3() { List<Statistics> list = new ArrayList<Statistics>(); for (int i = 0; i < 10; i++) { list.add(StatisticsUtil.statisticsOf(new ArrayDouble(i))); } Statistics stats = StatisticsUtil.statisticsOf(list); assertThat(stats.getAverage(), equalTo(4.5)); assertThat(stats.getStdDev(), equalTo(2.8722813232690143)); assertThat(stats.getRange().getMinimum(), equalTo(0.0)); assertThat(stats.getRange().getMaximum(), equalTo(9.0)); assertThat(stats.getCount(), equalTo(10)); }
@Test public void statisticsOf4() { Statistics stats = StatisticsUtil.statisticsOf(new ArrayDouble(1, 3, 5, Double.NaN, -1, 7)); assertThat(stats.getAverage(), equalTo(3.0)); assertThat(stats.getStdDev(), equalTo(2.8284271247461903)); assertThat(stats.getRange().getMinimum(), equalTo(-1.0)); assertThat(stats.getRange().getMaximum(), equalTo(7.0)); assertThat(stats.getCount(), equalTo(5)); }
@Test public void statisticsOf5() { Statistics stats = StatisticsUtil.statisticsOf(new ArrayDouble(1, 3, 5, -1, 7)); stats = StatisticsUtil.statisticsOf(Arrays.asList(stats)); assertThat(stats.getAverage(), equalTo(3.0)); assertThat(stats.getStdDev(), equalTo(2.8284271247461903)); assertThat(stats.getRange().getMinimum(), equalTo(-1.0)); assertThat(stats.getRange().getMaximum(), equalTo(7.0)); assertThat(stats.getCount(), equalTo(5)); }