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

import javax.annotation.Resource;
import net.ranides.assira.collection.sets.ASortedSet;
import net.ranides.assira.collection.suite.IteratorTester;
import net.ranides.assira.test.TCollection;
import net.ranides.assira.test.TCollection.TItem;
import net.ranides.assira.test.TCollection.TItems;
import net.ranides.assira.junit.TestContract;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public final class ASortedSetTester<K> {
    
    @Resource(name = "collection!")
    private TCollection<K> $var;

    @TestContract
    public void basicHead(ASortedSet<K> target) {
        SetTester.assertHead($var, target, $var.list().values());
        $var.list(4, 7, 5, 3, 6).into(target);
        SetTester.assertHead($var, target, $var.list(3, 4, 5, 6, 7).values());
    }

    @TestContract
    public void basicTail(ASortedSet<K> target) {
        SetTester.assertTail($var, target, $var.list().values());
        $var.list(4, 7, 5, 3, 6).into(target);
        SetTester.assertTail($var, target, $var.list(3, 4, 5, 6, 7).values());
    }

    @TestContract
    public void basicSub(ASortedSet<K> target) {
        SetTester.assertTail($var, target, $var.list().values());
        $var.list(4, 7, 5, 3, 6).into(target);
        SetTester.assertTail($var, target, $var.list(3, 4, 5, 6, 7).values());
    }
    
    @TestContract
    public void basicIterator(ASortedSet<K> target) {
        TItems<K> list1 = $var.list();
        TItems<K> list2 = $var.list(3, 4, 5, 6, 7);
        
        IteratorTester.orderIterator(target.iterator(), 0, list1.values());
        
        $var.list(4, 7, 5, 3, 6).into(target);
        
        IteratorTester.orderIterator(target.iterator(), 0, list2.values());
    }

    @TestContract
    public void basicIteratorFrom(ASortedSet<K> target) {
        TItems<K> list1 = $var.list();
        TItems<K> list2 = $var.list(3, 4, 5, 6, 7);
        TItem<K> item = $var.item(4);
        
        IteratorTester.orderIterator(target.iterator(item.value()), 0, list1.values());
        
        $var.list(4, 7, 5, 3, 6).into(target);
        
        IteratorTester.orderIterator(target.iterator(item.value()), 2, list2.values());
    }
    
    @TestContract
    public void basicSubsetIteratorFrom(ASortedSet<K> target) {
        TItems<K> list = $var.list(3, 4, 5, 6, 7);
        TItem<K> item = $var.item(4);

        $var.list(4, 7, 5, 3, 6, 1, 8).into(target);
        ASortedSet<K> map = target.subSet($var.item(1).value(), $var.item(8).value());
        
        IteratorTester.subIterator(map.iterator(item.value()), 2, list.values());
    }

}
