@Test public void test3() { Layout l = new Layout(); assertThat(l.getNumberOfItems(), equalTo(0)); assertThat(l.getItems().size(), equalTo(0)); Item item = new Item(ItemType.Triplet, new Cell(0, 0)); for (int i = 0; i < Layout.MAX_ITEM_NUM; i++) { assertTrue(l.canAddMore()); l = l.addItem(item); assertTrue(l.hasItem(item)); assertThat(l.getNumberOfItems(), equalTo(i + 1)); } assertFalse(l.canAddMore()); try { l.addItem(item); fail(); } catch (IllegalStateException e) { } assertThat(l, not(equalTo(Layout.createDefault()))); List<Item> items = new ArrayList<>(l.getItems()); for (Item i : items) { assertThat(i, not(sameInstance(item))); assertThat(i, equalTo(item)); l = l.removeItem(item.createClone()); } assertThat(l.getNumberOfItems(), equalTo(0)); assertThat(l, equalTo(new Layout())); try { l.removeItem(item); fail(); } catch (IllegalArgumentException e) { } }
@Test public void test4() { Layout l = new Layout(); assertThat(l.getNumberOfItems(), equalTo(0)); assertThat(l.getItems().size(), equalTo(0)); Item item = new Item(ItemType.Triplet, new Cell(3, 2)); l = l.addItem(item); assertThat(l.getNumberOfItems(), equalTo(1)); assertThat(l.getIndex(item), equalTo(0)); assertThat(l.getItem(new Cell(3, 1)), equalTo(item)); assertThat(l.getItem(new Cell(3, 2)), equalTo(item)); assertThat(l.getItem(new Cell(3, 3)), equalTo(item)); assertThat(l.getItem(new Cell(3, 4)), nullValue()); assertThat(l.getItem(new Cell(3, 0)), nullValue()); l = l.moveItem(item, new Cell(6, 8)); assertThat(l.getIndex(item), nullValue()); item = l.getItems().get(0); assertThat(l.getItem(new Cell(6, 6)), nullValue()); assertThat(l.getItem(new Cell(6, 7)), equalTo(item)); assertThat(l.getItem(new Cell(6, 8)), equalTo(item)); assertThat(l.getItem(new Cell(6, 9)), equalTo(item)); assertThat(l.getItem(new Cell(6, 10)), nullValue()); l = l.removeItem(new Item(ItemType.Triplet, new Cell(6, 8))); assertThat(l.getNumberOfItems(), equalTo(0)); item = new Item(ItemType.Sun, new Cell(-4, -7)); l = l.addItem(item); for (int row = -5; row <= -3; row++) { for (int col = -8; col <= -6; col++) { assertThat(l.getItem(new Cell(row, col)), equalTo(item)); } } assertThat(l.getItem(new Cell(-2, -2)), nullValue()); }