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

import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import net.ranides.assira.junit.TestResource;
import net.ranides.assira.collection.maps.AOpenMap;
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>}
 * @param <K>
 * @param <V>
 */
public final class AHashMapTester<K,V> {

    @TestResource(name = "map!")
    private TMap<K,V> $var;
    
    @TestContract
    public void basicFastIterator(AOpenMap<K, V> target) {
        $var.list(1,2,3,4,5).into(target);
        
        Iterator<Map.Entry<K, V>> iterator = target.fastEntryIterator();

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