### Question:
ExtraMath { public static double average( double x, double y) { double result; boolean sameSign; if (x >= 0.0) { if (y >= 0.0) { sameSign = true; } else { sameSign = false; } } else { if (y >= 0.0) { sameSign = false; } else { sameSign = true; } } if (sameSign) { if (y >= x) { result = x + ((y - x) / 2.0); } else { result = y + ((x - y) / 2.0); } } else { result = (x + y) / 2.0; } assert true && result >= Math.min(x, y) && result <= Math.max(x, y) && (false || Math.nextUp(Math.min(x, y)) >= Math.max(x, y) || (result != x && result != y) ) : "average(" + x + ", " + y + ") = " + result; return result; }  static double modulus(
        double base,
        double x); static int modulus(
        int base,
        int x); static double centeredModulus(
        double base,
        double x); static double nextUp(
        double base,
        double x); static double nextDown(
        double base,
        double x); static double average(
        double x,
        double y); static double midpoint(
        double base,
        double x,
        double y); static double geometricMean(
        double x,
        double y);  }### Answer:
@Test public void testAverage() { final double[] NUMBERS = {-7.345, -1.0, 0.0, 1.0, 2.0}; for (double x : NUMBERS) { Assert.assertEquals(x, ExtraMath.average(x, x), 0.0); double xp = Math.nextAfter(x, Double.POSITIVE_INFINITY); double xpp = Math.nextAfter(xp, Double.POSITIVE_INFINITY); double xm = Math.nextAfter(x, Double.NEGATIVE_INFINITY); double xmm = Math.nextAfter(xm, Double.NEGATIVE_INFINITY); Assert.assertEquals(x, ExtraMath.average(xm, xp), 0.0); Assert.assertEquals(x, ExtraMath.average(xp, xm), 0.0); Assert.assertEquals(x, ExtraMath.average(xmm, xpp), 0.0); Assert.assertEquals(x, ExtraMath.average(xpp, xmm), 0.0); Assert.assertEquals(xp, ExtraMath.average(x, xpp), 0.0); Assert.assertEquals(xp, ExtraMath.average(xpp, x), 0.0); Assert.assertEquals(xm, ExtraMath.average(xmm, x), 0.0); Assert.assertEquals(xm, ExtraMath.average(x, xmm), 0.0); for (double y : NUMBERS) { double min = Math.min(x, y); double mean = ExtraMath.average(x, y); double max = Math.max(x, y); double meanReverse = ExtraMath.average(y, x); double meanNegative = ExtraMath.average(-y, -x); Assert.assertTrue(min + " <= " + mean, min <= mean); Assert.assertTrue(mean + " <= " + max, mean <= max); Assert.assertEquals(mean, meanReverse, 0.0); if (mean == 0.0) { Assert.assertEquals(x, -y, 0.0); } if (x == -y) { Assert.assertEquals(0.0, mean, 0.0); } Assert.assertEquals(-mean, meanNegative, 0.0); } } }