package net.ranides.assira.collection.lists;

import java.util.Arrays;
import net.ranides.assira.collection.iterators.IntListIterator;
import net.ranides.assira.collection.suite.IteratorTester;
import net.ranides.assira.junit.NewAssert;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author msieron
 */
public class IntRangeTest {

	@Test
	public void testIterator() {
		IteratorTester.listIterator(new IntRange(0, 5).listIterator(), 0, new Integer[]{0,1,2,3,4});
		IteratorTester.listIterator(new IntRange(0, 5).listIterator(2), 2, new Integer[]{0,1,2,3,4});
		assertTrue(true);
	}
	
	@Test
	public void testGet() {
		IntRange range = new IntRange(4, 10);
		assertEquals(6, range.size());
		
		assertEquals(4, range.getInt(0));
		assertEquals(5, range.getInt(1));
		assertEquals(6, range.getInt(2));
		assertEquals(9, range.getInt(5));
		
		NewAssert.assertThrows(IndexOutOfBoundsException.class, ()->{
			range.getInt(6);
		});
		
		NewAssert.assertSymEquals(Arrays.asList(4,5,6,7,8,9), range);
	}
	
	@Test
	public void testConstness() {
		IntRange range = new IntRange(4, 10);
		
		NewAssert.assertThrows(UnsupportedOperationException.class, ()->{
			range.add(7);
		});
		NewAssert.assertThrows(UnsupportedOperationException.class, ()->{
			range.addElements(0, new int[]{2,3});
		});
		NewAssert.assertThrows(UnsupportedOperationException.class, ()->{
			range.set(0, 0);
		});
		NewAssert.assertThrows(UnsupportedOperationException.class, ()->{
			range.remove(0);
		});
		
		NewAssert.assertThrows(UnsupportedOperationException.class, ()->{
			IntListIterator i = range.iterator();
			i.next();
			i.remove();
		});
		
		NewAssert.assertThrows(UnsupportedOperationException.class, ()->{
			IntListIterator i = range.iterator();
			i.next();
			i.add(0);
		});
		
		NewAssert.assertThrows(UnsupportedOperationException.class, ()->{
			IntListIterator i = range.iterator();
			i.next();
			i.set(0);
		});

	}
	
}
