예제 #1
1
  @Test
  public void checkGetElements() {
    assumeTrue(dataStructure instanceof INodeListDatastructureReadable);
    IReadable tempDS = (IReadable) dataStructure;

    int size = 20;
    IElement singleDummy;

    ArrayList<IElement> dummies = new ArrayList<>();
    for (int i = 0; i < size; i++) {
      singleDummy = mock(this.elementClass);

      /*
       * Nodes are stored with an index, so set it please!
       */
      if (singleDummy instanceof Node) {
        when(((Node) singleDummy).getIndex()).thenReturn(i);
      }
      if (singleDummy instanceof Edge) {
        when(((Edge) singleDummy).getHashString()).thenReturn("" + i);
      }

      assertTrue(tempDS.add(singleDummy));
      dummies.add(singleDummy);
    }

    Collection<IElement> elements = tempDS.getElements();

    /*
     * Check for the proper size and content
     */
    assertEquals(dummies.size(), elements.size());
    assertTrue(dummies.containsAll(elements));
    assertTrue(elements.containsAll(dummies));
  }
예제 #2
0
  @Test
  public void checkNoOverwriting() {
    assumeTrue(dataStructure instanceof INodeListDatastructureReadable);
    IReadable tempDS = (IReadable) dataStructure;

    IElement dummy1 = mock(elementClass);
    IElement dummy2 = mock(elementClass);

    if (Node.class.isAssignableFrom(elementClass)) {
      when(((Node) dummy1).getIndex()).thenReturn(1);
      when(((Node) dummy2).getIndex()).thenReturn(2);
    }
    if (Edge.class.isAssignableFrom(elementClass)) {
      when(((Edge) dummy1).getHashString()).thenReturn("1");
      when(((Edge) dummy2).getHashString()).thenReturn("2");
    }

    assertFalse(tempDS.contains(dummy1));
    assertFalse(tempDS.contains(dummy2));
    assertEquals(0, tempDS.size());

    assertTrue(tempDS.add(dummy1));
    assertTrue(tempDS.contains(dummy1));
    assertEquals(1, tempDS.size());

    assertTrue(tempDS.add(dummy2));
    assertTrue(tempDS.contains(dummy2));
    assertEquals(2, tempDS.size());

    assertTrue(tempDS.remove(dummy1));
    assertFalse(tempDS.contains(dummy1));
    assertEquals(1, tempDS.size());

    assertTrue(tempDS.add(dummy1));
    assertTrue(tempDS.contains(dummy1));
    assertEquals(2, tempDS.size());

    int count = 0;
    for (@SuppressWarnings("unused") IElement e : tempDS.getElements()) {
      count++;
    }
    assertEquals(tempDS.size(), count);
  }
예제 #3
0
  @Test
  public void checkGetRandom() {
    assumeTrue(dataStructure instanceof INodeListDatastructureReadable);
    IReadable tempDS = (IReadable) dataStructure;

    IElement[] dummies = new IElement[10];
    for (int i = 0; i < dummies.length; i++) {
      dummies[i] = mock(elementClass);
      if (dummies[i] instanceof Edge) when(((Edge) dummies[i]).getHashString()).thenReturn("" + i);
      tempDS.add(dummies[i]);
    }

    IElement random;
    for (int i = 0; i < 2 * dummies.length; i++) {
      random = tempDS.getRandom();
      assertNotNull(random);
      assertTrue(tempDS.contains(random));
    }
  }