/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.test.contracts.maps;

import java.util.Iterator;
import java.util.NoSuchElementException;
import net.ranides.assira.junit.TestResource;
import net.ranides.assira.collection.maps.IntOpenMap;
import net.ranides.assira.collection.maps.IntMap.IntEntry;
import net.ranides.test.data.TMap;
import static net.ranides.assira.junit.NewAssert.*;
import net.ranides.assira.junit.TestContract;

/**
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
public final class IntOpenMapTester<V> {

    @TestResource(name = "map!")
    private TMap<Integer,V> $var;
    
    @TestContract
    public void basicFastIterator(IntOpenMap<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());
    }
    
}
