Median { static int median (int x, int y, int z) { int m = z; if (y < z) { if (x < y) m = y; else if (x < z) m = x; } else { if (x > y) m = y; else if (x > z) m = x; } assert x == y || x == z ? m == x : true ; assert y == z ? m == y : true ; assert x < z && z < y ? m == z : true ; assert y < z && z < x ? m == z : true ; assert x < y && y < z ? m == y : true ; assert z < y && y < x ? m == y : true ; assert y < x && x < z ? m == x : true ; assert z < x && x < y ? m == x : true ; return m; }    }
@Test public void midIsFirst() { Assert.assertEquals(2, median(2, 1, 3)); }
@Test public void midIsLast() { Assert.assertEquals(2, median(1, 3, 2)); }
@Test public void midIsMiddle() { Assert.assertEquals(2, median(1, 2, 3)); }