Exemplo n.º 1
0
  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);
  }
Exemplo n.º 2
0
 @Test
 public void shouldReturnNorthDirectionInstanceWhenDirectionStringIsN()
     throws InvalidArgumentException {
   Direction north = DirectionFactory.getDirectionInstance("N");
   assertTrue(north instanceof NorthDirection);
 }
Exemplo n.º 3
0
 @Test(expected = InvalidArgumentException.class)
 public void shouldThrowInvalidArgumentExceptionWhenDirectionStringIsInvalid()
     throws InvalidArgumentException {
   Direction crap = DirectionFactory.getDirectionInstance("Sometext");
 }
Exemplo n.º 4
0
 @Test
 public void shouldReturnWestDirectionInstanceWhenDirectionStringIsW()
     throws InvalidArgumentException {
   Direction west = DirectionFactory.getDirectionInstance("W");
   assertTrue(west instanceof WestDirection);
 }
Exemplo n.º 5
0
 @Test
 public void shouldReturnEastDirectionInstanceWhenDirectionStringIsE()
     throws InvalidArgumentException {
   Direction east = DirectionFactory.getDirectionInstance("E");
   assertTrue(east instanceof EastDirection);
 }
Exemplo n.º 6
0
 @Test
 public void shouldReturnSouthDirectionInstanceWhenDirectionStringIsS()
     throws InvalidArgumentException {
   Direction south = DirectionFactory.getDirectionInstance("S");
   assertTrue(south instanceof SouthDirection);
 }