示例#1
0
  @Test
  public void addAndRemoveComponent() {
    Entity entity = new Entity();

    entity.add(new ComponentA());

    assertEquals(1, entity.getComponents().size());

    Bits componentBits = entity.getComponentBits();
    int componentAIndex = ComponentType.getIndexFor(ComponentA.class);

    for (int i = 0; i < componentBits.length(); ++i) {
      assertEquals(i == componentAIndex, componentBits.get(i));
    }

    assertNotNull(am.get(entity));
    assertNull(bm.get(entity));
    assertTrue(am.has(entity));
    assertFalse(bm.has(entity));

    entity.remove(ComponentA.class);

    assertEquals(0, entity.getComponents().size());

    for (int i = 0; i < componentBits.length(); ++i) {
      assertFalse(componentBits.get(i));
    }

    assertNull(am.get(entity));
    assertNull(bm.get(entity));
    assertFalse(am.has(entity));
    assertFalse(bm.has(entity));
  }
示例#2
0
  @Test
  public void addAndReturnComponent() {
    Entity entity = new Entity();
    ComponentA componentA = new ComponentA();
    ComponentB componentB = new ComponentB();

    assertEquals(componentA, entity.addAndReturn(componentA));
    assertEquals(componentB, entity.addAndReturn(componentB));

    assertEquals(2, entity.getComponents().size());
  }
示例#3
0
  @Test
  public void noComponents() {
    Entity entity = new Entity();

    assertEquals(0, entity.getComponents().size());
    assertTrue(entity.getComponentBits().isEmpty());
    assertNull(am.get(entity));
    assertNull(bm.get(entity));
    assertFalse(am.has(entity));
    assertFalse(bm.has(entity));
  }
示例#4
0
  @Test
  public void addSameComponent() {
    Entity entity = new Entity();

    ComponentA a1 = new ComponentA();
    ComponentA a2 = new ComponentA();

    entity.add(a1);
    entity.add(a2);

    assertEquals(1, entity.getComponents().size());
    assertTrue(am.has(entity));
    assertNotEquals(a1, am.get(entity));
    assertEquals(a2, am.get(entity));
  }