Пример #1
0
  public void testRemoveCard() {

    RemoveCardMove rcm =
        new RemoveCardMove(
            game.col4, new Card(Card.TEN, Card.SPADES), game.col1, game.col2, game.col3, game.col4);

    assertTrue(rcm.valid(game));

    assertTrue(rcm.doMove(game));

    // First three cards are the K/Q/J of spades and final column is empty
    assertEquals(new Card(Card.KING, Card.SPADES), game.col1.peek());
    assertEquals(new Card(Card.QUEEN, Card.SPADES), game.col2.peek());
    assertEquals(new Card(Card.JACK, Card.SPADES), game.col3.peek());
    assertTrue(game.col4.empty());

    assertTrue(rcm.undo(game));

    // Back to original
    assertEquals(new Card(Card.KING, Card.SPADES), game.col1.peek());
    assertEquals(new Card(Card.QUEEN, Card.SPADES), game.col2.peek());
    assertEquals(new Card(Card.JACK, Card.SPADES), game.col3.peek());
    assertEquals(new Card(Card.TEN, Card.SPADES), game.col4.peek());

    // invalid on empty
    game.col4.get();

    assertFalse(rcm.valid(game));
    assertFalse(rcm.doMove(game));
  }
Пример #2
0
  public void testMoveCard() {
    // first clear a space
    RemoveCardMove rcm =
        new RemoveCardMove(
            game.col4, new Card(Card.TEN, Card.SPADES), game.col1, game.col2, game.col3, game.col4);

    assertTrue(rcm.valid(game));
    assertTrue(rcm.doMove(game));

    // Now move King to the empty space. This move expects the card to already have
    // been retrieved from the column.
    Card c = game.col1.get();
    MoveCardMove mcm = new MoveCardMove(game.col1, c, game.col4);
    assertTrue(mcm.valid(game));
    assertTrue(mcm.doMove(game));

    // Back to original
    assertTrue(game.col1.empty());
    assertEquals(new Card(Card.QUEEN, Card.SPADES), game.col2.peek());
    assertEquals(new Card(Card.JACK, Card.SPADES), game.col3.peek());
    assertEquals(new Card(Card.KING, Card.SPADES), game.col4.peek());

    assertTrue(mcm.undo(game));

    // Back to original
    assertEquals(new Card(Card.KING, Card.SPADES), game.col1.peek());
    assertEquals(new Card(Card.QUEEN, Card.SPADES), game.col2.peek());
    assertEquals(new Card(Card.JACK, Card.SPADES), game.col3.peek());
    assertTrue(game.col4.empty());

    // invalid on empty
    game.col1.get();
  }