/*
 *  Draco Econometrics
 *  Copyright (C) 2006-2008 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.datamodel;

import static org.junit.Assert.*;

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

public class StatTableModelTest {

	private static final double[][] DATA = {{1.0,10.0},{3.0,30.0},{2.0,20.0}};
	private static final String[] HEADINGS = {"one","two"};  
	
	private StatTableModel model = null;
	
	@Before
	public void setUp() throws Exception {
		model = new StatTableModel(DATA,HEADINGS);
	}

	@After
	public void tearDown() throws Exception {
		model = null;
	}

	@Test
	public void testIsInitialModel() {
		assertFalse(model.isInitialModel());
		
		model = new StatTableModel();
		assertTrue(model.isInitialModel());
		
		model.setValueAt(new Integer(5), 0, 0);
		assertFalse(model.isInitialModel());
		
		model = new StatTableModel();
		model.addColumn();
		assertFalse(model.isInitialModel());
		
		model = new StatTableModel();
		model.getConstants().add(new Constant("cval",2.0));
		assertFalse(model.isInitialModel());
	}

	@Test
	public void testSortAscending() {
		model.sortAscending(0);
		
		for(int i=0;i<model.getRowCount();i++) {
			assertEquals(i+1,model.getVariable(0).get(i).intValue());
			assertEquals((i+1)*10,model.getVariable(1).get(i).intValue());
		}
	}

	@Test
	public void testSortDescending() {
		model.sortDescending(0);
		
		for(int i=0;i<model.getRowCount();i++) {
			assertEquals(model.getRowCount()-i,model.getVariable(0).get(i).intValue());
			assertEquals((model.getRowCount()-i)*10,model.getVariable(1).get(i).intValue());
		}
	}

}
