@Test
public void testMidpoint()
{

    final double BASE = 360.0;
    final double DELTA = Math.ulp(BASE);
    final double[] NUMBERS = {
        0.0, 12.3,
        90.0, 101.01,
        180.0, 222.2,
        270.0, 333.3,
        };
    String message;
    for (double x : NUMBERS)
    {
        message = "x = " + x;
        Assert.assertEquals(
            message,
            x,
            ExtraMath.midpoint(BASE, x, x),
            0.0);
        double xp = ExtraMath.nextUp(BASE, x);
        double xpp = ExtraMath.nextUp(BASE, xp);
        double xm = ExtraMath.nextDown(BASE, x);
        double xmm = ExtraMath.nextDown(BASE, xm);
        double midXmXp = ExtraMath.midpoint(BASE, xm, xp);
        double midXmmXpp = ExtraMath.midpoint(BASE, xmm, xpp);
        double midXXpp = ExtraMath.midpoint(BASE, x, xpp);
        double midXmmX = ExtraMath.midpoint(BASE, xmm, x);
        Assert.assertEquals(message, x, midXmXp, 0.0);
        Assert.assertTrue(
            message + ": "
                + midXmmXpp + " in {" + xm + ", " + x + "}",
            midXmmXpp == xm || midXmmXpp == x);
        Assert.assertEquals(message, xp, midXXpp, 0.0);
        Assert.assertEquals(message, xm, midXmmX, 0.0);
        assertEquals(
            message,
            BASE,
            ExtraMath.modulus(BASE, x + BASE/2.0),
            ExtraMath.midpoint(BASE, xp, xm),
            DELTA);
        assertEquals(
            message,
            BASE,
            ExtraMath.modulus(BASE, x + BASE/2.0),
            ExtraMath.midpoint(BASE, xpp, xmm),
            DELTA);
        assertEquals(
            message,
            BASE,
            ExtraMath.modulus(BASE, xp + BASE/2.0),
            ExtraMath.midpoint(BASE, xpp, x),
            DELTA);
        assertEquals(
            message,
            BASE,
            ExtraMath.modulus(BASE, xm + BASE/2.0),
            ExtraMath.midpoint(BASE, x, xmm),
            DELTA);
        for (double y : NUMBERS)
        {
            message = "x = " + x + ", y = " + y;
            double midpoint = ExtraMath.midpoint(BASE, x, y);
            if (x <= y)
            {
                Assert.assertTrue(
                    message + ": " + x + " <= " + midpoint,
                    x <= midpoint);
                Assert.assertTrue(
                    message + ": " + midpoint + " <= " + y,
                    midpoint <= y);
            }
            else
            {
                Assert.assertTrue(
                    message + ": "
                        + midpoint + " < " + y + " or "
                        + x + " < " + midpoint,
                    midpoint <= y || x <= midpoint);
            }
            if (x != y)
            {
                double midpointReverse =
                    ExtraMath.midpoint(BASE, y, x);
                assertEquals(
                    message,
                    BASE,
                    ExtraMath.modulus(BASE, midpoint + BASE/2.0),
                    midpointReverse,
                    DELTA);
            }
            double midpointOpposite = ExtraMath.midpoint(
                BASE,
                ExtraMath.modulus(BASE, x + BASE/2.0),
                ExtraMath.modulus(BASE, y + BASE/2.0));
            assertEquals(
                message,
                BASE,
                ExtraMath.modulus(BASE, midpoint + BASE/2.0),
                midpointOpposite,
                DELTA);
        }
    }
}