Angle { public Direction getNearestDirection() { int round = angle >>> 9; int up = angle & 256; if (up != 0) { ++round; } switch (round & 3) { case 0: return SOUTH; case 1: return WEST; case 2: return NORTH; case 3: return EAST; default: throw new IllegalStateException(); } }  Direction getNearestDirection();  }
@Test public void getNearestDirection() { Angle angle = new Angle(512 + 10); assertEquals(WEST, angle.getNearestDirection()); angle = new Angle(512 + 256 + 1); assertEquals(NORTH, angle.getNearestDirection()); }