@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);
        }
    }
}