예제 #1
0
  @Test
  public void testRoomExists() throws Exception {

    // create room in shape of '+' with five total
    // rooms ; one in center and one at each extremity
    Room base = new Room("test");
    Room up = new Room("test1");
    Room down = new Room("test2");
    Room left = new Room("test3");
    Room right = new Room("test4");

    // set base
    base.setLocation(up, down, left, right);

    // set up
    up.setLocation(Direction.NORTH, null);
    up.setLocation(Direction.SOUTH, base);
    up.setLocation(Direction.EAST, null);
    up.setLocation(Direction.WEST, null);

    // are there rooms around base?
    assertTrue(base.roomExists(Direction.NORTH));
    assertTrue(base.roomExists(Direction.SOUTH));
    assertTrue(base.roomExists(Direction.EAST));
    assertTrue(base.roomExists(Direction.WEST));

    // are there rooms around up?
    assertFalse(up.roomExists(Direction.NORTH));
    assertTrue(up.roomExists(Direction.SOUTH));
    assertFalse(up.roomExists(Direction.EAST));
    assertFalse(up.roomExists(Direction.WEST));
  }
예제 #2
0
  @Test
  public void testsetLocation() throws Exception {
    // create room in shape of '+' with five total
    // rooms ; one in center and one at each extremity
    Room base = new Room("test");
    Room up = new Room("test1");
    Room down = new Room("test2");
    Room left = new Room("test3");
    Room right = new Room("test4");

    // call method to set north = up, etc
    base.setLocation(Direction.NORTH, up);
    base.setLocation(Direction.SOUTH, down);
    base.setLocation(Direction.EAST, left);
    base.setLocation(Direction.WEST, right);

    // test if objects reference same memory location
    assertEquals(base.getNorth(), up);
    assertEquals(base.getSouth(), down);
    assertEquals(base.getEast(), left);
    assertEquals(base.getWest(), right);
  }