/*
 * @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.Map;
import java.util.NoSuchElementException;
import javax.annotation.Resource;
import net.ranides.assira.collection.maps.AHashMap;
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>
 * @param <K>
 * @param <V>
 */
public final class AHashMapTester<K,V> {

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