Esempio n. 1
0
 @Test
 public void constructor() {
   final Pie pie = new Pie(bus);
   for (@Pie.Slot int slot = Pie.SLOT_TOP_LEFT; slot < Pie.NUMBER_SLOTS; slot++) {
     assertThat(pie.getPiece(slot), is(equalTo(Piece.EMPTY)));
   }
 }
Esempio n. 2
0
  @Test
  public void tryPlacePiece() {
    final Pie pie = new Pie(bus);

    assertThat(pie.tryPlacePiece(Pie.SLOT_TOP_LEFT, Piece.ORANGE), is(true));
    assertThat(pie.tryPlacePiece(Pie.SLOT_TOP_LEFT, Piece.GREEN), is(false));

    assertThat(pie.tryPlacePiece(Pie.SLOT_TOP_CENTER, Piece.ORANGE), is(true));
    assertThat(pie.tryPlacePiece(Pie.SLOT_TOP_CENTER, Piece.ORANGE), is(false));

    assertThat(occurrencesOf(events, pie.thisChanged), is(equalTo(2)));
  }
Esempio n. 3
0
  @Test
  public void canPlacePiece() {
    final Pie pie = new Pie(bus);

    assertThat(pie.canPlacePiece(Pie.SLOT_TOP_LEFT, Piece.GREEN), is(true));
    assertThat(pie.tryPlacePiece(Pie.SLOT_TOP_LEFT, Piece.GREEN), is(true));
    assertThat(pie.canPlacePiece(Pie.SLOT_TOP_LEFT, Piece.PURPLE), is(false));

    assertThat(pie.canPlacePiece(Pie.SLOT_TOP_RIGHT, Piece.ORANGE), is(true));
    assertThat(pie.tryPlacePiece(Pie.SLOT_TOP_RIGHT, Piece.ORANGE), is(true));
    assertThat(pie.canPlacePiece(Pie.SLOT_TOP_RIGHT, Piece.GREEN), is(false));
  }
Esempio n. 4
0
  @Test
  public void serialization() {
    final Pie outPie = new Pie(bus);
    outPie.tryPlacePiece(Pie.SLOT_TOP_LEFT, Piece.ORANGE);
    outPie.tryPlacePiece(Pie.SLOT_TOP_RIGHT, Piece.PURPLE);
    outPie.tryPlacePiece(Pie.SLOT_BOTTOM_CENTER, Piece.GREEN);

    final Bundle savedState = new Bundle();
    outPie.saveState(savedState);

    final Pie inPie = new Pie(bus);
    inPie.restoreState(savedState);

    assertThat(inPie, is(equalTo(outPie)));
  }
Esempio n. 5
0
  @Test
  public void isFull() {
    final Pie pie = new Pie(bus);

    assertThat(pie.isFull(), is(false));

    pie.tryPlacePiece(Pie.SLOT_TOP_LEFT, Piece.ORANGE);
    assertThat(pie.isFull(), is(false));

    for (@Pie.Slot int slot = Pie.SLOT_TOP_LEFT; slot < Pie.NUMBER_SLOTS; slot++) {
      pie.tryPlacePiece(slot, Piece.ORANGE);
    }

    assertThat(pie.isFull(), is(true));
  }
Esempio n. 6
0
  @Test
  public void reset() {
    final Pie pie = new Pie(bus);

    assertThat(pie.isFull(), is(false));

    for (@Pie.Slot int slot = Pie.SLOT_TOP_LEFT; slot < Pie.NUMBER_SLOTS; slot++) {
      pie.tryPlacePiece(slot, Piece.ORANGE);
    }

    assertThat(pie.isFull(), is(true));

    pie.reset();

    assertThat(pie.isFull(), is(false));

    assertThat(occurrencesOf(events, pie.thisChanged), is(equalTo(7)));
  }
Esempio n. 7
0
 public static void main(String[] args) {
   Pie x = new Pie();
   x.f();
 }
Esempio n. 8
0
  @Test
  public void isSingleColor() {
    final Pie pie = new Pie(bus);

    assertThat(pie.isSingleColor(), is(false));

    pie.tryPlacePiece(Pie.SLOT_TOP_LEFT, Piece.ORANGE);
    pie.tryPlacePiece(Pie.SLOT_TOP_CENTER, Piece.PURPLE);
    pie.tryPlacePiece(Pie.SLOT_TOP_RIGHT, Piece.PURPLE);
    pie.tryPlacePiece(Pie.SLOT_BOTTOM_LEFT, Piece.GREEN);
    pie.tryPlacePiece(Pie.SLOT_BOTTOM_CENTER, Piece.GREEN);
    pie.tryPlacePiece(Pie.SLOT_BOTTOM_RIGHT, Piece.PURPLE);

    assertThat(pie.isSingleColor(), is(false));

    pie.reset();

    pie.tryPlacePiece(Pie.SLOT_TOP_LEFT, Piece.ORANGE);
    pie.tryPlacePiece(Pie.SLOT_TOP_CENTER, Piece.ORANGE);
    pie.tryPlacePiece(Pie.SLOT_TOP_RIGHT, Piece.ORANGE);
    pie.tryPlacePiece(Pie.SLOT_BOTTOM_LEFT, Piece.ORANGE);
    pie.tryPlacePiece(Pie.SLOT_BOTTOM_CENTER, Piece.ORANGE);
    pie.tryPlacePiece(Pie.SLOT_BOTTOM_RIGHT, Piece.ORANGE);

    assertThat(pie.isSingleColor(), is(true));
  }