Exemplo n.º 1
0
 @Test
 public void testAdd2() {
   set.add(key1, key1);
   assertEquals(1, set.size());
   assertEquals(1, set.add(key1, key2));
   assertEquals(2, set.size());
 }
Exemplo n.º 2
0
 @Test
 public void testClear() {
   set.add(1, 2, 3);
   set.clear();
   assertEquals(0, set.size());
   assertEquals(0, set.toArray().length);
 }
Exemplo n.º 3
0
  @Test
  public void testConstructorFromContainer() {
    IntOpenHashSet list2 = new IntOpenHashSet();
    list2.add(1, 3, 5);

    set = new IntDoubleLinkedSet(list2);
    assertEquals(3, set.size());
    assertSortedListEquals(list2.toArray(), set.toArray());
  }
Exemplo n.º 4
0
  @Test
  public void testRemove() {
    set.add(0, 1, 2, 3, 4);

    assertTrue(set.remove(2));
    assertFalse(set.remove(2));
    assertEquals(4, set.size());
    assertSortedListEquals(set.toArray(), 0, 1, 3, 4);
  }
Exemplo n.º 5
0
  @Test
  public void testAdd() {
    assertTrue(set.add(key1));
    assertFalse(set.add(key1));
    assertEquals(1, set.size());

    assertTrue(set.contains(key1));
    assertFalse(set.contains(key2));
  }
Exemplo n.º 6
0
  @Test
  public void testRemoveAllFromLookupContainer() {
    set.add(0, 1, 2, 3, 4);

    IntOpenHashSet list2 = new IntOpenHashSet();
    list2.add(1, 3, 5);

    assertEquals(2, set.removeAll(list2));
    assertEquals(3, set.size());
    assertSortedListEquals(set.toArray(), 0, 2, 4);
  }
Exemplo n.º 7
0
  @Test
  public void testInitialCapacityAndGrowth() {
    for (int i = 0; i < 256; i++) {
      IntDoubleLinkedSet set = new IntDoubleLinkedSet(i, i);

      for (int j = 0; j < i; j++) {
        set.add(/* intrinsic:ktypecast */ j);
      }

      assertEquals(i, set.size());
    }
  }
Exemplo n.º 8
0
  @Test
  public void testRemoveAllWithPredicate() {
    set.add(0, key1, key2);

    assertEquals(
        1,
        set.removeAll(
            new IntPredicate() {
              public boolean apply(int v) {
                return v == key1;
              };
            }));

    assertSortedListEquals(set.toArray(), 0, key2);
  }
Exemplo n.º 9
0
  @Test
  public void testRetainAllWithPredicate() {
    set.add(0, key1, key2, 3, 4, 5);

    assertEquals(
        4,
        set.retainAll(
            new IntPredicate() {
              public boolean apply(int v) {
                return v == key1 || v == key2;
              };
            }));

    assertSortedListEquals(set.toArray(), key1, key2);
  }
Exemplo n.º 10
0
  /**
   * Run some random insertions/ deletions and compare the results against <code>java.util.HashSet
   * </code>.
   */
  @Test
  public void testAgainstHashMap() {
    final java.util.Random rnd = new java.util.Random(0x11223344);
    final java.util.HashSet<Integer> other = new java.util.HashSet<Integer>();

    for (int size = 1000; size < 20000; size += 4000) {
      other.clear();
      set.clear();

      for (int round = 0; round < size * 20; round++) {
        Integer key = rnd.nextInt(size);

        if (rnd.nextBoolean()) {
          assertEquals(other.add(key), set.add(key));
          assertTrue(set.contains(key));
        } else {
          assertEquals(other.remove(key), set.remove(key));
        }

        assertEquals(other.size(), set.size());
      }

      int[] actual = set.toArray();
      int[] expected = new int[other.size()];
      int i = 0;
      for (Integer v : other) expected[i++] = v;
      Arrays.sort(expected);
      Arrays.sort(actual);
      assertArrayEquals(expected, actual);
    }
  }
Exemplo n.º 11
0
  @Test
  public void testClone() {
    set.add(1, 2, 3);

    IntDoubleLinkedSet cloned = set.clone();
    cloned.remove(1);

    assertSortedListEquals(set.toArray(), 1, 2, 3);
    assertSortedListEquals(cloned.toArray(), 2, 3);
  }
Exemplo n.º 12
0
  @Test
  public void testFromMethod() {
    IntOpenHashSet list2 = new IntOpenHashSet();
    list2.add(1, 3, 5);

    IntDoubleLinkedSet s1 = IntDoubleLinkedSet.from(1, 3, 5);
    IntDoubleLinkedSet s2 = IntDoubleLinkedSet.from(1, 3, 5);

    assertSortedListEquals(list2.toArray(), s1.toArray());
    assertSortedListEquals(list2.toArray(), s2.toArray());
  }
Exemplo n.º 13
0
  @Test
  public void testAddAll() {
    IntDoubleLinkedSet set2 = new IntDoubleLinkedSet();
    set2.add(1, 2);
    set.add(0, 1);

    assertEquals(1, set.addAll(set2));
    assertEquals(0, set.addAll(set2));

    assertEquals(3, set.size());
    assertSortedListEquals(set.toArray(), 0, 1, 2);
  }
Exemplo n.º 14
0
  @Test
  public void testIterable() {
    set.add(1, 2, 2, 3, 4);
    set.remove(2);
    assertEquals(3, set.size());

    int count = 0;
    for (IntCursor cursor : set) {
      count++;
      assertTrue(set.contains(cursor.value));
    }
    assertEquals(count, set.size());

    set.clear();
    assertFalse(set.iterator().hasNext());
  }
Exemplo n.º 15
0
 @Test
 public void testAddVarArgs() {
   set.add(0, 1, 2, 1, 0);
   assertEquals(3, set.size());
   assertSortedListEquals(set.toArray(), 0, 1, 2);
 }
Exemplo n.º 16
0
 @Test
 public void testInitiallyEmpty() {
   assertEquals(0, set.size());
 }
Exemplo n.º 17
0
 @Test
 public void testToString() {
   assertEquals("[1, 3, 5]", IntDoubleLinkedSet.from(1, 3, 5).toString());
 }