예제 #1
0
  @Test
  public void checkIterator() {
    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);
      }

      dataStructure.add(singleDummy);
      dummies.add(singleDummy);
    }

    Iterator<IElement> elemIterator = dataStructure.iterator();
    while (elemIterator.hasNext()) {
      singleDummy = elemIterator.next();
      assertTrue(dummies.contains(singleDummy));
      dummies.remove(singleDummy);
    }
    assertTrue(dummies.isEmpty());
  }
예제 #2
0
  @Test
  public void checkResizement() {
    int initialSize = dataStructure.getDefaultSize();
    int goalSize = 10 * initialSize;

    assertEquals(0, dataStructure.size());

    IElement singleDummy;

    for (int i = 0; i < goalSize; 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);
      }

      dataStructure.add(singleDummy);
    }
    assertEquals(goalSize, dataStructure.size());
  }
예제 #3
0
  @Test
  public void checkDuplicateCalls() {
    IElement dummy = getDummy(elementClass);

    assertTrue(dataStructure.add(dummy));
    assertFalse(dataStructure.add(dummy));

    assertTrue(dataStructure.remove(dummy));
    assertFalse(dataStructure.remove(dummy));
  }
예제 #4
0
  @Test
  public void checkNullsInIterator() {
    IElement singleDummy;

    dataStructure.reinitializeWithSize(10);
    Iterator<IElement> elemIterator = dataStructure.iterator();
    while (elemIterator.hasNext()) {
      singleDummy = elemIterator.next();
      assertNotNull(singleDummy);
    }
  }
예제 #5
0
 @Test
 public void checkCorrectSize() {
   IElement[] dummies = new IElement[10];
   for (int i = 0; i < dummies.length; i++) {
     dummies[i] = mock(this.elementClass);
     if (Node.class.isAssignableFrom(this.elementClass))
       when(((Node) dummies[i]).getIndex()).thenReturn(i);
     if (dummies[i] instanceof Edge) when(((Edge) dummies[i]).getHashString()).thenReturn("" + i);
     assertTrue(dataStructure.add(dummies[i]));
   }
   assertEquals(dummies.length, dataStructure.size());
 }
예제 #6
0
  @Test
  public void checkNullsInGetElements() {
    assumeTrue(dataStructure instanceof INodeListDatastructureReadable);
    INodeListDatastructureReadable tempDS = (INodeListDatastructureReadable) dataStructure;

    dataStructure.reinitializeWithSize(10);
    for (IElement singleDummy : tempDS.getElements()) {
      assertNotNull(singleDummy);
    }
  }
예제 #7
0
 @Test
 public void checkAddAndRemove() {
   IElement dummy = mock(elementClass);
   if (dummy instanceof Edge) {
     when(((Edge) dummy).getHashString()).thenReturn("1");
   }
   assertFalse(dataStructure.contains(dummy));
   assertEquals(0, dataStructure.size());
   assertTrue(dataStructure.add(dummy));
   assertTrue(dataStructure.contains(dummy));
   assertEquals(1, dataStructure.size());
   assertTrue(dataStructure.remove(dummy));
   assertFalse(dataStructure.contains(dummy));
   assertEquals(0, dataStructure.size());
 }
예제 #8
0
  @SuppressWarnings("unchecked")
  @Test
  public void checkOnlyOneDatatype() {
    IElement dummy;
    int exceptionCounter = 0;

    /*
     * Checking whether add() throws the exception we want it to throw does
     * not cover all cases here - we want to ensure that really only
     * instances of one single element class can be stored, and *all* other
     * instance types are rejected
     *
     * The exception counter will be increased for each *allowed* class and
     * each *rejected* class. There should be no gap in between...
     */

    for (Class otherElementClass : GlobalTestParameters.elementClasses) {
      if (elementClass.isAssignableFrom(otherElementClass)) {
        assertTrue(
            "Datastructure "
                + dataStructure.getClass()
                + "["
                + this.elementClass
                + "] can't store "
                + otherElementClass
                + " even if it should",
            dataStructure.canStore(otherElementClass));
        exceptionCounter++;
        continue;
      }
      dummy = (IElement) mock(otherElementClass);

      boolean exceptionThrown = false;
      assertFalse(
          "Datastructure "
              + dataStructure.getClass()
              + "["
              + this.elementClass
              + "/"
              + dataStructure.getDataType()
              + "] can store "
              + otherElementClass
              + " even if it shouldn't",
          dataStructure.canStore(otherElementClass));

      try {
        dataStructure.add(dummy);
      } catch (RuntimeException e) {
        exceptionCounter++;
        exceptionThrown = true;
      }

      assertTrue("Whoopsie - whats up with " + otherElementClass, exceptionThrown);
      /*
       * So, this is thrown when the datastructure is not allowed to be
       * added to that list, but no exception is thrown. Common error:
       * add() has not called canAdd()
       */
    }

    assertEquals(GlobalTestParameters.elementClasses.length, exceptionCounter);
  }