예제 #1
0
  @Test
  public void testRemove() {
    Assert.assertFalse(this.set.remove(this.k2));
    Assert.assertFalse(this.set.remove(this.keyE));

    addFromArray(this.set, this.key0, this.key1, this.key2, this.key3, this.key4);

    Assert.assertTrue(this.set.remove(this.k2));
    Assert.assertFalse(this.set.remove(this.k2));
    Assert.assertEquals(4, this.set.size());
    TestUtils.assertSortedListEquals(this.set.toArray(), 0, 1, 3, 4);
  }
예제 #2
0
  @Test
  public void testIterable2() {
    addFromArray(this.set, this.keyE, this.key1, this.key2, this.key2, this.key3, this.key4);
    this.set.remove(this.k2);
    Assert.assertEquals(4, this.set.size());

    int counted = 0;
    for (final KTypeCursor<KType> cursor : this.set) {
      if (cursor.index == getKeys(this.set).length) {

        Assert.assertTrue(this.isAllocatedDefaultKey(this.set));
        TestUtils.assertEquals2(this.keyE, cursor.value);
        counted++;
        continue;
      }

      Assert.assertTrue(this.set.contains(cursor.value));
      TestUtils.assertEquals2(cursor.value, this.getKeys(this.set)[cursor.index]);
      counted++;
    }
    Assert.assertEquals(counted, this.set.size());

    this.set.clear();
    Assert.assertFalse(this.set.iterator().hasNext());
  }
예제 #3
0
  @Test
  public void testAdd() {
    Assert.assertTrue(this.set.add(this.key1));
    Assert.assertFalse(this.set.add(this.key1));
    Assert.assertEquals(1, this.set.size());

    Assert.assertTrue(this.set.add(this.keyE));
    Assert.assertFalse(this.set.add(this.keyE));

    Assert.assertEquals(2, this.set.size());

    Assert.assertTrue(this.set.add(this.key2));
    Assert.assertFalse(this.set.add(this.key2));

    Assert.assertEquals(3, this.set.size());
  }
예제 #4
0
 @Test
 public void testNullKey() {
   this.set.add((KType) null);
   Assert.assertEquals(1, this.set.size());
   Assert.assertTrue(this.set.contains(null));
   Assert.assertTrue(this.set.remove(null));
   Assert.assertEquals(0, this.set.size());
   Assert.assertFalse(this.set.contains(null));
 }
예제 #5
0
  @Test
  /*! #if ($TemplateOptions.KTypeGeneric) !*/
  @SuppressWarnings("unchecked")
  /*! #end !*/
  public void testEquals() {
    final KTypeSet<KType> l0 = getFrom();
    Assert.assertEquals(l0, createNewSetInstance());

    KTypeSet<KType> l1 = getFrom(this.k1, this.k2, this.k3, this.k4, this.k5);
    KTypeSet<KType> l2 = getFrom(this.k2, this.k1);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    Assert.assertFalse(l1.equals(null));
    Assert.assertFalse(l2.equals(null));

    l2.add(this.k5);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.k4);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.k3);
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l1.add(this.keyE);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.keyE);

    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l2.remove(this.keyE);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.add(this.keyE);

    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l2.remove(this.k7); // not present, sets are still OK
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l2.remove(this.k2);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l1.remove(this.k2);
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    l1.add(this.k7);
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l2.clear();
    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);

    l1.clear();
    Assert.assertEquals(l1, l2);
    Assert.assertEquals(l2, l1);
    // Check consistency with hashCode:
    Assert.assertEquals(l1.hashCode(), l2.hashCode());

    // Same size, different contents
    l1 = getFrom(this.k1, this.k2, this.k3, this.k4, this.k5);
    l2 = getFrom(this.k2, this.k1, this.key5, this.key6, this.key7);

    Assert.assertNotEquals(l1, l2);
    Assert.assertNotEquals(l2, l1);
  }