package com.github.kratorius.cuckoohash;

import junit.framework.TestCase;

import java.util.Map;

public class CuckooHashMapTest extends TestCase {
  @SuppressWarnings("UnnecessaryBoxing")
  public void testMap() {
    Map<Character,Boolean> m = new CuckooHashMap<Character, Boolean>();
    put(m, 'A', true,  null);
    put(m, 'A', false, true); // Guaranteed identical by JLS
    put(m, 'B', true,  null);
    put(m, new Character('A'), false, false);

    try {
      m.get(null);
      fail("map did not reject null key");
    } catch (NullPointerException e) {
      // expected.
    }

    try {
      m.put(null, true);
      fail("map did not reject null key");
    } catch (NullPointerException e) {
      // expected.
    }

    try {
      m.put('C', null);
    } catch (NullPointerException e) {
      fail("Rejected null value");
    }
  }

  private static void put(Map<Character, Boolean> m,
                          Character key,
                          Boolean value,
                          Boolean oldValue) {
    if (oldValue != null) {
      assertTrue(m.containsValue(oldValue));
      assertTrue(m.values().contains(oldValue));
    }

    assertEquals(m.put(key, value), oldValue);
    assertEquals(m.get(key), value);

    assertTrue(m.containsKey(key));
    assertTrue(m.containsValue(value));

    assertTrue(m.values().contains(value));

    assertFalse(m.isEmpty());
  }
}

@@ -67,16 +67,41 @@
 estCase;
+%0Aimport org.junit.Before;
 %0A%0Aimport
@@ -173,46 +173,65 @@
 %7B%0A  
-@SuppressWarnings(%22UnnecessaryBoxing%22)
+private CuckooHashMap%3CCharacter, Boolean%3E mCB;%0A%0A  @Before
 %0A  p
@@ -245,14 +245,12 @@
 oid 
-testMa
+setU
 p() 
@@ -259,75 +259,108 @@
     
-Map%3CCharacter,Boolean%3E m = new CuckooHashMap%3CCharacter, Boolean%3E();
+mCB = new CuckooHashMap%3C%3E();%0A  %7D%0A%0A  @SuppressWarnings(%22UnnecessaryBoxing%22)%0A  public void testMap() %7B
 %0A   
@@ -361,24 +361,26 @@
  %7B%0A    put(m
+CB
 , 'A', true,
@@ -397,16 +397,18 @@
    put(m
+CB
 , 'A', f
@@ -460,16 +460,18 @@
    put(m
+CB
 , 'B', t
@@ -492,16 +492,18 @@
    put(m
+CB
 , new Ch
@@ -549,16 +549,18 @@
 %0A      m
+CB
 .get(nul
@@ -684,24 +684,26 @@
 ry %7B%0A      m
+CB
 .put(null, t
@@ -833,16 +833,18 @@
 %0A      m
+CB
 .put('C'
@@ -937,16 +937,418 @@
  %7D%0A  %7D%0A%0A
+  public void testContainsKey() %7B%0A    try %7B%0A      mCB.containsKey(null);%0A      fail(%22accepted null key%22);%0A    %7D catch (NullPointerException e) %7B%0A      // Expected.%0A    %7D%0A%0A    mCB.put('A', true);%0A    mCB.put('B', true);%0A    mCB.put('C', true);%0A%0A    assertTrue(mCB.containsKey('A'));%0A    assertTrue(mCB.containsKey('B'));%0A    assertTrue(mCB.containsKey('C'));%0A    assertFalse(mCB.containsKey('D'));%0A  %7D%0A%0A
   privat

Test containsKey