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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author ranides
 */
public class JoinListTest {
    
    public JoinListTest() {
    }

    @Test
    public void testIterator() {
        List<Integer> a = new ArrayList<>( Arrays.asList(0) );
        List<Integer> b = new ArrayList<>( Arrays.asList(1, 2, 3, 4) );
        List<Integer> c = new ArrayList<>( Arrays.asList(5, 6) );
        List<Integer> d = new ArrayList<>( Arrays.asList(7, 8, 9) );
        
        JoinList<Integer> list = new JoinList<>();
        
        list.join(a);
        list.join(b);
        list.join(c);
        list.join(d);
        
        ListIterator<Integer> iterator = list.listIterator();
        
        assertEquals(0, (int)iterator.next());
        assertEquals(1, (int)iterator.next());
        assertEquals(2, (int)iterator.next());
        assertEquals(3, (int)iterator.next());
        assertEquals(4, (int)iterator.next());
        assertEquals(5, (int)iterator.next());
        assertEquals(5, (int)iterator.previous());
        assertEquals(4, (int)iterator.previous());
        assertEquals(3, (int)iterator.previous());
        assertEquals(2, (int)iterator.previous());
        assertEquals(1, (int)iterator.previous());
        assertEquals(1, (int)iterator.next());
        assertEquals(2, (int)iterator.next());
        assertEquals(3, (int)iterator.next());
        assertEquals(3, (int)iterator.previous());
        assertEquals(2, (int)iterator.previous());
        assertEquals(1, (int)iterator.previous());
        assertEquals(0, (int)iterator.previous());
        
        assertEquals(Arrays.asList(0,1,2,3,4,5,6,7,8,9), list);
        
        a.clear();
        assertEquals(Arrays.asList(1,2,3,4,5,6,7,8,9), list);
        
        a.add(77);
        b.add(55);
        c.clear();
        assertEquals(Arrays.asList(77, 1, 2, 3, 4, 55, 7, 8, 9), list);
        
        assertTrue(true);
    }
}
