コード例 #1
0
  @Test
  public void testConstructors() {
    DefaultIndexer<String> instance = new DefaultIndexer<String>();
    assertTrue(instance.isEmpty());
    assertTrue(instance.valueSet().isEmpty());
    assertTrue(instance.valueList().isEmpty());
    assertTrue(instance.asMap().isEmpty());

    instance = new DefaultIndexer<String>(123);
    assertTrue(instance.isEmpty());
    assertTrue(instance.valueSet().isEmpty());
    assertTrue(instance.valueList().isEmpty());
    assertTrue(instance.asMap().isEmpty());

    List<String> values = Arrays.asList("a", "c", new String("a"), null, "b");
    instance = new DefaultIndexer<String>(values);
    assertEquals(4, instance.size());
    assertEquals(4, instance.valueSet().size());
    assertEquals(4, instance.valueList().size());
    assertEquals(4, instance.asMap().size());
    assertTrue(instance.valueSet().containsAll(values));
    assertTrue(instance.valueList().containsAll(values));
    assertTrue(instance.asMap().keySet().containsAll(values));
    assertEquals(0, (int) instance.getIndex("a"));
    assertEquals(3, (int) instance.getIndex("b"));
    assertEquals(1, (int) instance.getIndex("c"));
    assertEquals(2, (int) instance.getIndex(null));
  }
コード例 #2
0
  /** Test of valueSet method, of class DefaultIndexer. */
  @Test
  public void testValueSet() {
    DefaultIndexer<String> instance = new DefaultIndexer<String>();
    assertTrue(instance.valueSet().isEmpty());

    instance.add("something");
    assertEquals(1, instance.valueSet().size());
    assertTrue(instance.valueSet().contains("something"));

    List<String> values = Arrays.asList("a", "c", new String("a"), null, "b");
    instance.addAll(values);
    assertEquals(5, instance.valueSet().size());
    assertTrue(instance.valueSet().contains("something"));
    assertTrue(instance.valueSet().containsAll(values));
  }
コード例 #3
0
  /** Test of clone method, of class DefaultIndexer. */
  @Test
  public void testClone() {
    DefaultIndexer<String> instance = new DefaultIndexer<String>();
    DefaultIndexer<String> clone = instance.clone();
    assertNotSame(instance, clone);
    assertNotSame(clone, instance.clone());

    instance.add("a");
    assertEquals(0, (int) instance.getIndex("a"));
    assertNull(clone.getIndex("a"));
    assertTrue(clone.isEmpty());
    assertTrue(clone.valueSet().isEmpty());
    assertTrue(clone.valueList().isEmpty());

    instance.add("b");
    clone = instance.clone();
    assertEquals(2, clone.size());
    assertEquals(instance.valueList(), clone.valueList());
    assertEquals(instance.asMap(), clone.asMap());
    assertEquals(0, (int) clone.getIndex("a"));
    assertEquals(1, (int) clone.getIndex("b"));
  }