package com.github.kratorius.cuckoohash;

import junit.framework.TestCase;

import java.util.AbstractMap;
import java.util.Map;
import java.util.Set;

/**
 * Tests for entrySet(), keySet() and values().
 */
public class ViewsTest extends TestCase {
  @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
  public void testEmptyEntrySet() {
    CuckooHashMap<String, Integer> m = new CuckooHashMap<>();
    assertTrue(m.entrySet().isEmpty());
  }

  public void testSimpleEntrySet() {
    CuckooHashMap<String, Integer> m = new CuckooHashMap<>();

    m.put("key1", 1);
    assertEquals(1, m.entrySet().size());

    Map.Entry<String, Integer> item = m.entrySet().iterator().next();
    assertEquals(1, (int) item.getValue());
  }

  public void testLargeEntrySet() {
    final int size = 1024;
    CuckooHashMap<String, Integer> m = new CuckooHashMap<>();

    for (int i = 0; i < size; i++){
      m.put("key-" + i, 100);
    }

    Set<Map.Entry<String, Integer>> entrySet = m.entrySet();
    assertEquals(size, entrySet.size());
    assertEquals(size, m.size());

    for (int i = 0; i < size; i++) {
      assertTrue(entrySet.contains(new AbstractMap.SimpleEntry<>("key-" + i, 100)));
    }
  }

  // TODO keySet() and values()
}

@@ -95,24 +95,53 @@
 bstractMap;%0A
+import java.util.Collection;%0A
 import java.
@@ -146,24 +146,24 @@
 a.util.Map;%0A
-
 import java.
@@ -1233,36 +1233,1398 @@
 %0A%0A  
-// TODO keySet() and values()
+public void testKeySet() %7B%0A    final int size = 1024;%0A    CuckooHashMap%3CString, Integer%3E m = new CuckooHashMap%3C%3E();%0A%0A    for (int i = 0; i %3C size; i++)%7B%0A      m.put(%22key-%22 + i, i);%0A    %7D%0A%0A    // keySet() returns a set and therefore there's no guarantee on the ordering of the keys.%0A    Set%3CString%3E keys = m.keySet();%0A    assertEquals(size, keys.size());%0A%0A    for (int i = 0; i %3C size; i++)%7B%0A      assertTrue(keys.contains(%22key-%22 + i));%0A    %7D%0A%0A    // Override a key.%0A    m.put(%22key-123%22, 2134);%0A    keys = m.keySet();%0A    assertEquals(size, keys.size());%0A%0A    for (int i = 0; i %3C size; i++)%7B%0A      assertTrue(keys.contains(%22key-%22 + i));%0A    %7D%0A  %7D%0A%0A  public void testValues_unique() %7B%0A    final int size = 1024;%0A    CuckooHashMap%3CString, Integer%3E m = new CuckooHashMap%3C%3E();%0A%0A    for (int i = 0; i %3C size; i++)%7B%0A      m.put(%22key-%22 + i, i);%0A    %7D%0A%0A    Collection%3CInteger%3E values = m.values();%0A    assertEquals(size, values.size());%0A%0A    for (int i = 0; i %3C size; i++)%7B%0A      assertTrue(values.contains(i));%0A    %7D%0A  %7D%0A%0A  public void testValues_duplicates() %7B%0A    final int size = 1024;%0A    CuckooHashMap%3CString, Integer%3E m = new CuckooHashMap%3C%3E();%0A%0A    for (int i = 0; i %3C size; i++)%7B%0A      m.put(%22key-%22 + i, i / 2);%0A    %7D%0A%0A    Collection%3CInteger%3E values = m.values();%0A    assertEquals(size, values.size());%0A%0A    for (int i = 0; i %3C size; i++)%7B%0A      assertTrue(values.contains(i / 2));%0A    %7D%0A  %7D
 %0A%7D%0A

Add missing tests for keySet() and values()