package eu.danieldk.fsadict.collections;

import eu.danieldk.fsadict.DictionaryBuilderException;
import eu.danieldk.fsadict.categories.Tests;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.HashMap;
import java.util.Map;

/**
 * Unit tests for {@link ImmutableStringIntMap}.
 */
@Category(Tests.class)
public class ImmutableStringIntTest {
    private Map<String, Integer> d_check1;
    private Map<String, Integer> d_check2;

    @Before
    public void initialize() {
        d_check1 = new HashMap<String, Integer>() {{
            put("Pulp Fiction", 9);
            put("The Godfather", 9);
            put("Dumb and Dumber", 3);
        }};

        d_check2 = new HashMap<String, Integer>() {{
            put("Miles Davis", 9);
            put("John Zorn", 9);
            put("Thelonious Monk", 8);
            put("The White Stripes", 8);
            put("Canned Heat", 3);
        }};
    }

    @Test
    public void containsTest() throws DictionaryBuilderException {
        ImmutableStringIntMap test = new ImmutableStringIntMap.Builder().putAll(d_check1).build();

        for (Map.Entry<String, Integer> entry : d_check1.entrySet())
            Assert.assertTrue(test.contains(entry.getKey()));

        for (Map.Entry<String, Integer> entry : d_check2.entrySet())
            Assert.assertFalse(test.contains(entry.getKey()));

    }

    @Test
    public void getOrElseTest() throws DictionaryBuilderException

    {
        ImmutableStringIntMap test = new ImmutableStringIntMap.Builder().putAll(d_check1).build();

        for (Map.Entry<String, Integer> entry : d_check1.entrySet())
            Assert.assertEquals(entry.getValue().intValue(), test.getOrElse(entry.getKey(), -1));

        for (Map.Entry<String, Integer> entry : d_check2.entrySet())
            Assert.assertEquals(-1, test.getOrElse(entry.getKey(), -1));
    }


}

@@ -281,37 +281,9 @@
 til.
-HashMap;%0Aimport java.util.Map
+*
 ;%0A%0A/
@@ -1490,16 +1490,11 @@
 tion
-%0A%0A   
  %7B%0A
+
     
@@ -1818,32 +1818,32 @@
 ck2.entrySet())%0A
-
             Asse
@@ -1906,11 +1906,428 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void iteratorTest() throws DictionaryBuilderException %7B%0A        ImmutableStringIntMap test = new ImmutableStringIntMap.Builder().putAll(d_check1).build();%0A%0A        Set%3CString%3E isiKeys = new HashSet%3CString%3E();%0A        Iterator%3CString%3E iter = test.keyIterator();%0A        while (iter.hasNext())%0A            isiKeys.add(iter.next());%0A%0A%0A        Assert.assertEquals(d_check1.keySet(), isiKeys);%0A    %7D%0A%0A
 %0A%7D%0A

Add a unit test for key-based iteration of maps.