MetricsUtil { public static double addToAverage(double oldCount, double oldAverage, double newCount, double newTotalTime) { if (newCount==0) { return oldAverage; } double newAverage = newTotalTime / newCount; return ((oldCount) / (newCount + oldCount) * oldAverage) + (newCount / (newCount + oldCount) * newAverage); }  static double addAverages(double oldCount,
                                     double oldAverage,
                                     double newCount,
                                     double newAverage); static double addToAverage(double oldCount,
                                      double oldAverage,
                                      double newCount,
                                      double newTotalTime); static final String GLOBAL_GROUP; }
@Test void addToAverage() { double average = 1.0; double avergeCount = 1.0; double newAverage = MetricsUtil.addToAverage(avergeCount, average, 1.0, 1.0); assertEquals(1.0, newAverage, DELTA); newAverage = MetricsUtil.addToAverage(avergeCount, average, 20.0, 20.0); assertEquals(1.0, newAverage, DELTA); newAverage = MetricsUtil.addToAverage(avergeCount, average, 0, 0); assertEquals(1.0, newAverage, DELTA); }