/*
 * @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 javax.annotation.Resource;
import net.ranides.assira.collection.maps.BlockMap;
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 BlockMapTester<K,V> {
    
    @Resource(name = "map!")
    private TMap<K,V> $var;

    @TestContract
    public void basicTrim(BlockMap<K,V> target) {
        $var.range(1024).into(target);
        target.clear();
        $var.range(128).into(target);
        assertTrue(target.trim());
    }
    
    @TestContract
    public void basicTrimF(BlockMap<K,V> target) {
        $var.range(1024).into(target);
        assertTrue(target.trim());
    }
    
    @TestContract
    public void basicTrimN1(BlockMap<K,V> target) {
        basicTrim(target, 5*32, 32, 1024);
    }
    
    @TestContract
    public void basicTrimN2(BlockMap<K,V> target) {
        assertThrows(IllegalArgumentException.class, () -> 
            basicTrim(target, 5*32, 32, 1)
        );
    }
    
    @TestContract
    public void basicTrimN3(BlockMap<K,V> target) {
        basicTrim(target, 5*32, 32, 32);
    }
    
    private void basicTrim(BlockMap<K,V> target, int put1st, int put2nd, int n) {
        $var.range(put1st).into(target);
        target.clear();
        $var.range(put2nd).into(target);
        target.trim(n);
    }
    
}
