package net.greypanther.fastutil.tests;

import static org.junit.Assert.*;

import java.util.Collections;
import java.util.Map.Entry;

import org.junit.Test;

import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntMaps;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;

public final class Int2IntMapTest {
  @Test
  public void testMapIteratorNextRemove() {
    Int2IntMap map = new Int2IntOpenHashMap();
    ObjectIterator<Entry<Integer, Integer>> iterator = map.entrySet().iterator();

    assertFalse(iterator.hasNext());
    iterator.next();
    iterator.remove();
  }

  @Test
  public void testArrayMapEntrySetSupportsRemoveAll() {
    Int2IntMap map = new Int2IntArrayMap();
    assertFalse(map.entrySet().removeAll(Collections.singleton("TEST")));
  }

  @Test(expected = IllegalStateException.class)
  public void testArrayMapEmptyEntrySetThrowsExceptionOnIteratorRemove() {
    ObjectIterator<Entry<Integer, Integer>> iterator = new Int2IntArrayMap().entrySet().iterator();

    assertFalse(iterator.hasNext());
    iterator.remove();
  }

  @Test
  public void testMapValuesShouldSupportClear() {
    Int2IntMap map = new Int2IntArrayMap(Int2IntMaps.singleton(42, 24));
    map.values().clear();
    assertTrue(map.isEmpty());
  }

  @Test
  public void testMapValuesShouldSupportRemove() {
    Int2IntMap map = new Int2IntArrayMap(Int2IntMaps.singleton(42, 24));
    map.values().remove(24);
    assertTrue(map.isEmpty());
  }

  @Test
  public void testMapValuesShouldSupportRemoveAll() {
    Int2IntMap map = new Int2IntArrayMap(Int2IntMaps.singleton(42, 24));
    map.values().removeAll(Collections.singleton(24));
    assertTrue(map.isEmpty());
  }
}

@@ -1798,11 +1798,402 @@
 ());%0A  %7D
+%0A%0A  @Test%0A  public void testSingletonMapEqualsShouldCheckTheTypeOfParamters() %7B%0A    Int2IntMap map = Int2IntMaps.singleton(1, 2);%0A    assertFalse(map.equals(Collections.singletonMap(null, 2)));%0A    assertFalse(map.equals(Collections.singletonMap(1, null)));%0A    assertFalse(map.equals(Collections.singletonMap(%22foo%22, 2)));%0A    assertFalse(map.equals(Collections.singletonMap(1, %22foo%22)));%0A  %7D
 %0A%7D%0A

Add tests for singleton maps