private Pair<Integer, Integer> walk( final Set<Coordinate> visited, final Coordinate[] shape1Coords, final Coordinate[] shape2Coords, final int start1, final int start2, final DirectionFactory factory) { final int upPos = takeBiggestStep( visited, shape2Coords[start2], shape1Coords, factory.createLeftFootDirection(start1, shape1Coords.length)); // even if the left foot was stationary, try to move the right foot final int downPos = takeBiggestStep( visited, shape1Coords[upPos], shape2Coords, factory.createRightFootDirection(start2, shape2Coords.length)); // if the right step moved, then see if another l/r step can be taken if (downPos != start2) { return walk(visited, shape1Coords, shape2Coords, upPos, downPos, factory); } return Pair.of(upPos, start2); }
@Test public void shouldReturnNorthDirectionInstanceWhenDirectionStringIsN() throws InvalidArgumentException { Direction north = DirectionFactory.getDirectionInstance("N"); assertTrue(north instanceof NorthDirection); }
@Test(expected = InvalidArgumentException.class) public void shouldThrowInvalidArgumentExceptionWhenDirectionStringIsInvalid() throws InvalidArgumentException { Direction crap = DirectionFactory.getDirectionInstance("Sometext"); }
@Test public void shouldReturnWestDirectionInstanceWhenDirectionStringIsW() throws InvalidArgumentException { Direction west = DirectionFactory.getDirectionInstance("W"); assertTrue(west instanceof WestDirection); }
@Test public void shouldReturnEastDirectionInstanceWhenDirectionStringIsE() throws InvalidArgumentException { Direction east = DirectionFactory.getDirectionInstance("E"); assertTrue(east instanceof EastDirection); }
@Test public void shouldReturnSouthDirectionInstanceWhenDirectionStringIsS() throws InvalidArgumentException { Direction south = DirectionFactory.getDirectionInstance("S"); assertTrue(south instanceof SouthDirection); }