Example #1
0
 public void testClear() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   map.clear();
   assertEquals(0, map.size());
 }
Example #2
0
 public void testRemove() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertEquals("hello", map.remove(1));
   assertEquals(1, map.size());
   assertNull(map.remove(3));
 }
Example #3
0
 public void testPut() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertEquals("hello", map.put(1, "hellooooo"));
 }
Example #4
0
 public void testIsEmpty() {
   IntHashMap map = new IntHashMap();
   assertTrue(map.isEmpty());
   assertNull(map.put(1, "hello"));
   assertEquals(1, map.size());
   assertFalse(map.isEmpty());
 }
Example #5
0
 public void testContainsKey() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertTrue(map.containsKey(1));
   assertTrue(map.containsKey(2));
   assertFalse(map.containsKey(3));
 }
Example #6
0
 public void testContainsValue() {
   IntHashMap map = new IntHashMap();
   assertNull(map.put(1, "hello"));
   assertNull(map.put(2, "world"));
   assertEquals(2, map.size());
   assertTrue(map.containsValue("hello"));
   assertTrue(map.containsValue("world"));
   assertFalse(map.containsValue("goodbye"));
   try {
     map.containsValue(null);
     fail();
   } catch (NullPointerException e) {
   }
 }
Example #7
0
  public void testConstructor() {
    try {
      new IntHashMap(-1, 0.0f);
      fail();
    } catch (IllegalArgumentException e) {
      assertEquals("Illegal Capacity: -1", e.getMessage());
    }
    try {
      new IntHashMap(1, 0.0f);
      fail();
    } catch (IllegalArgumentException e) {
      assertEquals("Illegal Load: 0.0", e.getMessage());
    }
    new IntHashMap(0, 1.0f);

    try {
      new IntHashMap(-1);
      fail();
    } catch (IllegalArgumentException e) {
      assertEquals("Illegal Capacity: -1", e.getMessage());
    }
    IntHashMap map1 = new IntHashMap(0);
    assertEquals(0, map1.size());
  }