/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j.indexing.map;

import static org.junit.Assert.*;

import org.junit.Test;

public class MinimalMapTest {

    @Test
    public void size_1() throws Exception {
	MinimalMap<MockEntry> map = new MockMap();
	assertEquals(0, map.size());
	String a = "a";
	map.get(a);
	assertEquals(1, map.size());
	map.get(a);
	assertEquals(1, map.size());
	map.get("b");
	assertEquals(2, map.size());
    }

    @Test
    public void get_1() throws Exception {
	MinimalMap<MockEntry> map = new MockMap();
	String a = "a";
	MockEntry x = map.get(a);
	MockEntry y = map.get(a);
	assertEquals(x, y);
    }

    static class MockMap extends MinimalMap<MockEntry> {

	@Override
	protected MockEntry[] createInitialArray(int size) {
	    return new MockEntry[size];
	}

	@Override
	protected MockEntry createEntry(Object key, int hashCode) {
	    return new MockEntry(key, hashCode);
	}

    }

    static class MockEntry implements MinimalMapEntry<MockEntry> {

	private final Object key;
	private final int hashCode;
	private MockEntry next;

	public MockEntry(Object key, int hashCode) {
	    this.key = key;
	    this.hashCode = hashCode;
	}

	@Override
	public int getHashCode() {
	    return hashCode;
	}

	@Override
	public Object getKey() {
	    return key;
	}

	@Override
	public MockEntry next() {
	    return next;
	}

	@Override
	public void setNext(MockEntry nextEntry) {
	    next = nextEntry;
	}

    }

}

@@ -521,17 +521,41 @@
 id size_
-1
+sizeGrowsWithAddedEntries
 () throw
@@ -647,77 +647,19 @@
 );%0A%09
-String a = %22a%22;%0A%09map.get(a);%0A%09assertEquals(1, map.size());%0A%09map.get(a
+map.get(%22a%22
 );%0A%09
@@ -769,17 +769,43 @@
 oid get_
-1
+createEntryAndRetrieveEntry
 () throw
@@ -951,12 +951,497 @@
 als(
-x, y
+1, map.size());%0A%09assertEquals(x, y);%0A    %7D%0A%0A    @Test%0A    public void get_createNewEntryForSameKeyWhenRemoved() throws Exception %7B%0A%09MinimalMap%3CMockEntry%3E map = new MockMap();%0A%09String a = %22a%22;%0A%09MockEntry x = map.get(a);%0A%09map.remove(a);%0A%09MockEntry y = map.get(a);%0A%09assertNotSame(x, y);%0A%0A    %7D%0A%0A    @Test%0A    public void remove_sizeDecrementsUponRemoval() throws Exception %7B%0A%09MinimalMap%3CMockEntry%3E map = new MockMap();%0A%09String a = %22a%22;%0A%09map.get(a);%0A%09map.remove(a);%0A%09assertEquals(0, map.size()
 );%0A 

Add tests for MinimalMap; rename old tests