Ejemplo n.º 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));
  }
Ejemplo n.º 2
0
  /** Test of add method, of class DefaultIndexer. */
  @Test
  public void testAdd() {
    DefaultIndexer<String> instance = new DefaultIndexer<String>();
    assertTrue(instance.isEmpty());

    assertEquals(0, (int) instance.add("a"));
    assertEquals(1, (int) instance.add("b"));
    assertEquals(2, (int) instance.add("another"));
    assertEquals(1, (int) instance.add(new String("b")));
    assertEquals(3, (int) instance.add(null));
    assertEquals(3, (int) instance.add(null));
    assertEquals(0, (int) instance.add("a"));
    assertEquals(4, (int) instance.add("something else"));
  }
Ejemplo n.º 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"));
  }
Ejemplo n.º 4
0
  /** Test of addAll method, of class DefaultIndexer. */
  @Test
  public void testAddAll() {
    DefaultIndexer<String> instance = new DefaultIndexer<String>();
    assertTrue(instance.isEmpty());

    instance.add("something");

    List<String> values = Arrays.asList("a", "c", new String("a"), null, "b");
    instance.addAll(values);

    assertEquals(5, instance.size());
    assertEquals(0, (int) instance.getIndex("something"));
    assertEquals(1, (int) instance.getIndex("a"));
    assertEquals(4, (int) instance.getIndex("b"));
    assertEquals(2, (int) instance.getIndex("c"));
    assertEquals(3, (int) instance.getIndex(null));

    instance.addAll(values);
    assertEquals(0, (int) instance.getIndex("something"));
    assertEquals(1, (int) instance.getIndex("a"));
    assertEquals(4, (int) instance.getIndex("b"));
    assertEquals(2, (int) instance.getIndex("c"));
    assertEquals(3, (int) instance.getIndex(null));
  }