예제 #1
0
  @Test
  public void test2() {
    Layout l = Layout.createDefault();

    l = l.randomize();
    assertThat(l, not(equalTo(Layout.createDefault())));
    assertThat(l.getNumberOfItems(), equalTo(Layout.createDefault().getNumberOfItems()));
  }
예제 #2
0
  @Test
  public void test5() {
    Layout l = Layout.createDefault();

    for (Item item : l.getItems()) {
      l = l.moveItem(item, item.getCenter());
    }

    assertThat(l, equalTo(Layout.createDefault()));
  }
예제 #3
0
 @Test
 public void test7() {
   Layout l = Layout.createDefault();
   String s = StringUtils.insertWhitespaces(l.serialize(), 1.0f, 3);
   Layout ls = Layout.deserialize(s);
   assertThat(ls, not(sameInstance(l)));
   assertThat(ls, equalTo(l));
   assertThat(ls.equals(l), is(true));
   assertThat(ls.hashCode(), equalTo(l.hashCode()));
 }
예제 #4
0
  @Test
  public void test1() {
    Layout l = Layout.createDefault();

    List<Item> items = l.getItems();
    assertThat(items.size(), equalTo(l.getNumberOfItems()));
    assertThat(l.getNumberOfItems(), not(equalTo(0)));
    for (int i = 0; i < items.size(); i++) {
      Item item = items.get(i);
      assertThat(l.hasItem(item), is(true));
      assertThat(l.getIndex(item), equalTo(i));
    }

    Layout l2 = new Layout(items);
    assertThat(l2, not(sameInstance(l)));
    assertThat(l2.getNumberOfItems(), equalTo(l.getNumberOfItems()));
    assertThat(l2, equalTo(l));
    assertThat(l, equalTo(l2));
    assertThat(l2.hashCode(), equalTo(l.hashCode()));

    Layout l3 = l2.createClone();
    assertThat(l3, not(sameInstance(l2)));
    assertThat(l3, not(sameInstance(l)));
    assertThat(l3, equalTo(l2));
    assertThat(l3, equalTo(l));
    assertThat(l3.hashCode(), equalTo(l2.hashCode()));
    assertThat(l3.hashCode(), equalTo(l.hashCode()));

    Layout l4 = Layout.deserialize(l3.serialize());
    assertThat(l4, not(sameInstance(l3)));
    assertThat(l4, equalTo(l3));
    assertThat(l4, equalTo(l2));
    assertThat(l4, equalTo(l));

    Layout l5 = Layout.deserialize(new StringReader(l4.serialize()));
    assertThat(l5, not(sameInstance(l3)));
    assertThat(l5, equalTo(l3));
    assertThat(l5, equalTo(l2));
    assertThat(l5, equalTo(l));
    assertThat(l5, equalTo(Layout.createDefault()));
  }
예제 #5
0
  @Test
  public void test9() {
    Layout l = Layout.createDefault();
    List<Item> defItems = Arrays.asList(Layout.getDefaultItems());
    assertThat(l.getItems(), equalTo(defItems));

    Item item = l.getItem(new Cell(20, 5));
    assertThat(item, notNullValue());
    assertThat(l.getIndex(item), equalTo(8));

    l = l.moveItem(item, new Cell(20, 6));
    assertThat(l.getItems(), not(equalTo(defItems)));

    item = l.getItem(new Cell(20, 6));
    assertThat(item, notNullValue());
    l = l.moveItem(item, new Cell(20, 5));
    assertThat(l.getItems(), equalTo(defItems));
  }
예제 #6
0
  @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) {
    }
  }
예제 #7
0
 @Test
 public void test8() {
   Layout l = Layout.createDefault();
   List<Item> defItems = Arrays.asList(Layout.getDefaultItems());
   assertThat(l.getItems(), equalTo(defItems));
 }