/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection.suite.maps;

import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.annotation.Resource;
import net.ranides.assira.collection.maps.IntHashMap;
import net.ranides.assira.collection.maps.IntMap.IntEntry;
import net.ranides.assira.test.TMap;
import static net.ranides.assira.junit.NewAssert.*;
import net.ranides.assira.junit.TestContract;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public final class IntHashMapTester<K,V> {

    @Resource(name = "map!")
    private TMap<Integer,V> $var;
    
    @TestContract
    public void basicFastIterator(IntHashMap<V> target) {
        $var.list(1,2,3,4,5).into(target);
        
        Iterator<IntEntry<V>> iterator = target.fastEntryIterator();

        IntEntry<V> last = null;
        while(iterator.hasNext()) {
            IntEntry<V> entry = iterator.next();
            assertEquals(target.get(entry.getKey()), entry.getValue());
            if(last != null) {
                assertSame(last, entry);
            }
            last = entry;
        }
        
        assertThrows(NoSuchElementException.class, ()-> iterator.next());
    }
    
}
