import static org.junit.Assert.*;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

/**
 * 
 */

/**Reference tests for the Array2D lab.
 * @author Nancy Harris
 * @version V1
 *
 */
public class ReferenceTest_Array2D
{
	private Array2D[] list;
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		list = new Array2D[5];
		list[0] = new Array2D(null);
		list[1] = new Array2D( new double[][] {{ 5.25}});
		list[2] = new Array2D( new double [][] {{1, 2, 3}, {1, 2}, { 1, 2, 3, 4}});
		list[3] = new Array2D( new double [][] {{ 1, 2, 3}, null, {1, 2, 3, 4}});
		list[4] = new Array2D( new double [][] {{ 1, 2, 3}, {-1, -2, -3}, {1, 2, 3}});
	}
		
	@Test
	public void testIsRow()
	{
		Assert.assertTrue("error in isRow method", list[1].isRow(0) );
		Assert.assertFalse("error in isRow method", list[2].isRow(4));
		Assert.assertTrue("error in isRow method", list[3].isRow(1) );
		Assert.assertTrue("error in isRow method", list[2].isRow(2));
	}
	@Test
	public void testIsCol()
	{
		Assert.assertTrue("error in isCol method", list[1].isCol(0) );
		Assert.assertFalse("error in isCol method", list[2].isCol(4));
		Assert.assertTrue("error in isCol method", list[3].isCol(3) );
		Assert.assertTrue("error in isCol method", list[2].isCol(3));
	}

	@Test
	public void testgetColumnTotal()
	{
		Assert.assertEquals("error in getColumnTotal method", 5.25 ,list[1].getColumnTotal(0) );
		Assert.assertEquals("error in getColumnTotal method", 3.0 ,list[2].getColumnTotal(0) );
		Assert.assertEquals("error in getColumnTotal method", 4.0 ,list[3].getColumnTotal(3) );
		Assert.assertEquals("error in getColumnTotal method", 4.0 ,list[3].getColumnTotal(1) );
	}
	
	@Test
	public void testgetRowTotal()
	{
		Assert.assertEquals("error in getRowTotal method", 5.25 ,list[1].getRowTotal(0) );
		Assert.assertEquals("error in getRowTotal method", 10.0 ,list[2].getRowTotal(2) );
		Assert.assertEquals("error in getRowTotal method", 10.0 ,list[3].getRowTotal(2) );
		Assert.assertEquals("error in getRowTotal method", -6.0 ,list[4].getRowTotal(1) );
	}
	@Test
	public void testHighestInRow()
	{
		Assert.assertEquals("error in getHighestInRow method", 5.25 ,list[1].getHighestInRow(0) );
		Assert.assertEquals("error in getHighestInRow method", 2.0 ,list[2].getHighestInRow(1) );
		Assert.assertEquals("error in getHighestInRow method", -1.0 ,list[4].getHighestInRow(1) );
	}
	@Test
	public void testLowestInRow()
	{
		Assert.assertEquals("error in getHighestInRow method", 5.25 ,list[1].getLowestInRow(0) );
		Assert.assertEquals("error in getHighestInRow method", 1.0 ,list[2].getLowestInRow(1) );
		Assert.assertEquals("error in getHighestInRow method", -3.0 ,list[4].getLowestInRow(1) );
	}
	@Test
	public void testgetTotal()
	{
		Assert.assertEquals("error in getTotal method", 5.25 ,list[1].getTotal() );
		Assert.assertEquals("error in getTotal method", 16.0 ,list[3].getTotal() );
		Assert.assertEquals("error in getTotal method", 6.0 ,list[4].getTotal() );
	}
	@Test(expected=ArrayIndexOutOfBoundsException.class) 
	public void testException()
	{
		list[0].getRowTotal(1);
	}
	@Test(expected=ArrayIndexOutOfBoundsException.class) 
	public void testException2()
	{
		list[0].getHighestInRow(1);
	}
}
