Example #1
0
 public void test_Issue6() {
   LongHashMap<String> t = new LongHashMap<String>();
   t.put(6447459, "aa");
   t.put(6382177, "bb");
   assertEquals("aa", t.get(6447459));
   assertEquals("bb", t.get(6382177));
   assertEquals("LongHashMap[6382177 => bb, 6447459 => aa]", t.toString());
 }
Example #2
0
 public void test2() {
   LongHashMap<String> v1 = new LongHashMap<String>();
   v1.put(1611, "1611");
   v1.put(15500, "15500");
   v1.put(9446, "9446");
   System.out.println(v1.get(9446));
   System.out.println(v1.toString());
   assertEquals(3, v1.size());
   assertEquals(v1.get(9446), "9446");
 }
Example #3
0
 public void testRandomCompare() {
   LongHashMap<String> v1 = new LongHashMap<String>();
   TreeMap<Long, String> v2 = new TreeMap<Long, String>();
   Random d = new Random();
   for (int i = 0; i < 1000; i++) {
     long key = d.nextInt() % 100;
     double random = d.nextDouble();
     if (random < 0.8) {
       //				System.out.println("put "+key);
       v1.put(key, "" + key);
       v2.put(key, "" + key);
     } else {
       //				System.out.println("remove "+key);
       v1.remove(key);
       v2.remove(key);
     }
     checkEquals(v1, v2);
   }
 }
Example #4
0
  public void testMapIter() {
    LongHashMap<String> v = new LongHashMap<String>();
    v.put(1L, "one");
    v.put(2L, "two");
    v.put(3L, "three");

    TreeMap<Long, String> v2 = new TreeMap<Long, String>();
    v2.put(1L, "one");
    v2.put(2L, "two");
    v2.put(3L, "three");

    TreeMap<Long, String> v3 = new TreeMap<Long, String>();
    LongMap.LongMapIterator<String> iter = v.longMapIterator();
    while (iter.moveToNext()) {
      v3.put(iter.key(), iter.value());
    }

    assertEquals(v2, v3);
  }
Example #5
0
  public void testAll() {
    LongHashMap<String> t = new LongHashMap<String>();
    t.put(1, "aa");
    t.put(2, "bb");
    t.put(2, "bb");
    t.put(4, "cc");
    t.put(9, "FF");
    assertEquals(4, t.size());
    t.remove(1);
    assertEquals(3, t.size());
    assertEquals(t.get(1), null);
    assertEquals(t.get(2), "bb");
    assertEquals(t.get(3), null);
    assertEquals(t.get(4), "cc");
    assertEquals(t.get(5), null);
    assertEquals(t.get(-1), null);
    assertEquals(t.get(9), "FF");

    Iterator<String> vals = t.valuesIterator();
    assertTrue(vals.hasNext());
    assertEquals(vals.next(), "FF");
    assertTrue(vals.hasNext());
    assertEquals(vals.next(), "cc");
    assertTrue(vals.hasNext());
    assertEquals(vals.next(), "bb");

    assertFalse(vals.hasNext());

    t.clear();
    assertEquals(0, t.size());
    t.put(2, "bb");
    assertEquals(1, t.size());
    assertEquals(t.get(1), null);
    assertEquals(t.get(2), "bb");
    assertEquals(t.get(3), null);
  }