Package org.apache.lucene.facet.collections

Examples of org.apache.lucene.facet.collections.IntHashSet


public class IntHashSetTest extends FacetTestCase {

  @Test
  public void test0() {
    IntHashSet set0 = new IntHashSet();

    assertEquals(0, set0.size());
    assertTrue(set0.isEmpty());
    set0.add(0);
    assertEquals(1, set0.size());
    assertFalse(set0.isEmpty());
    set0.remove(0);
    assertEquals(0, set0.size());
    assertTrue(set0.isEmpty());
  }
View Full Code Here


    assertTrue(set0.isEmpty());
  }

  @Test
  public void test1() {
    IntHashSet set0 = new IntHashSet();

    assertEquals(0, set0.size());
    assertTrue(set0.isEmpty());
    for (int i = 0; i < 1000; ++i) {
      set0.add(i);
    }
    assertEquals(1000, set0.size());
    assertFalse(set0.isEmpty());
    for (int i = 0; i < 1000; ++i) {
      assertTrue(set0.contains(i));
    }

    set0.clear();
    assertEquals(0, set0.size());
    assertTrue(set0.isEmpty());

  }
View Full Code Here

  }

  @Test
  public void test2() {
    IntHashSet set0 = new IntHashSet();

    assertEquals(0, set0.size());
    assertTrue(set0.isEmpty());
    for (int i = 0; i < 1000; ++i) {
      set0.add(1);
      set0.add(-382);
    }
    assertEquals(2, set0.size());
    assertFalse(set0.isEmpty());
    set0.remove(-382);
    set0.remove(1);
    assertEquals(0, set0.size());
    assertTrue(set0.isEmpty());

  }
View Full Code Here

  }

  @Test
  public void test3() {
    IntHashSet set0 = new IntHashSet();

    assertEquals(0, set0.size());
    assertTrue(set0.isEmpty());
    for (int i = 0; i < 1000; ++i) {
      set0.add(i);
    }

    for (int i = 0; i < 1000; i += 2) {
      set0.remove(i);
    }

    assertEquals(500, set0.size());
    for (int i = 0; i < 1000; ++i) {
      if (i % 2 == 0) {
        assertFalse(set0.contains(i));
      } else {
        assertTrue(set0.contains(i));
      }
    }

  }
View Full Code Here

  }

  @Test
  public void test4() {
    IntHashSet set1 = new IntHashSet();
    HashSet<Integer> set2 = new HashSet<Integer>();
    for (int i = 0; i < ArrayHashMapTest.RANDOM_TEST_NUM_ITERATIONS; ++i) {
      int value = random().nextInt() % 500;
      boolean shouldAdd = random().nextBoolean();
      if (shouldAdd) {
        set1.add(value);
        set2.add(value);
      } else {
        set1.remove(value);
        set2.remove(value);
      }
    }
    assertEquals(set2.size(), set1.size());
    for (int value : set2) {
      assertTrue(set1.contains(value));
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testMySet() {
    IntHashSet set = new IntHashSet();
    for (int j = 0; j < 100; ++j) {
      for (int i = 0; i < ArrayHashMapTest.RANDOM_TEST_NUM_ITERATIONS; ++i) {
        int value = random().nextInt() % 5000;
        boolean shouldAdd = random().nextBoolean();
        if (shouldAdd) {
          set.add(value);
        } else {
          set.remove(value);
        }
      }
      set.clear();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testToArray() {
    IntHashSet set = new IntHashSet();
    for (int j = 0; j < 100; ++j) {
      for (int i = 0; i < ArrayHashMapTest.RANDOM_TEST_NUM_ITERATIONS; ++i) {
        int value = random().nextInt() % 5000;
        boolean shouldAdd = random().nextBoolean();
        if (shouldAdd) {
          set.add(value);
        } else {
          set.remove(value);
        }
      }
      int[] vals = set.toArray();
      assertEquals(set.size(), vals.length);

      int[] realValues = new int[set.size()];
      int[] unrealValues = set.toArray(realValues);
      assertEquals(realValues, unrealValues);
      for (int value : vals) {
        assertTrue(set.remove(value));
      }
      for (int i = 0; i < vals.length; ++i) {
        assertEquals(vals[i], realValues[i]);
      }
    }
View Full Code Here

    }
  }

  @Test
  public void testZZMySet() {
    IntHashSet set = new IntHashSet();
    for (int j = 0; j < 100; ++j) {
      for (int i = 0; i < ArrayHashMapTest.RANDOM_TEST_NUM_ITERATIONS; ++i) {
        int value = random().nextInt() % 5000;
        boolean shouldAdd = random().nextBoolean();
        if (shouldAdd) {
          set.add(value);
        } else {
          set.remove(value);
        }
      }
      set.clear();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.facet.collections.IntHashSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.