package com.webfoot.prefuse;

/**
 * 
 */


import org.junit.Test;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
// import static org.junit.Assert.*;

import prefuse.data.Table;
import prefuse.data.io.DataIOException;
import prefuse.data.io.DelimitedTextTableReader;

/**
 * @author ducky@webfoot.com
 *
 */
public class HistogramTableTest extends TestCase {
	HistogramTable m_histoTable;
	Table m_dataTable;
	
	/**
	 * @throws java.lang.Exception
	 * 	 * The data file fisher.iris.txt has the following integer fields:
	 * SepalLength
	 * SepalWidth
	 * PetalLength
	 * PetalWidth
	 * Species
	 * and one String field
	 * Species Name
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		String dataFileName = "/fisher.iris.txt";
		try {
			m_dataTable = new DelimitedTextTableReader().readTable(dataFileName);
		} catch ( ArrayIndexOutOfBoundsException e ) {
			assertTrue(false);
		} catch ( DataIOException e) {
			assertTrue(false);
		}

		m_histoTable = new HistogramTable(m_dataTable, 50);
		// histoTable.printWholeTable();  // debug
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		// @@@ delete the old histogramtable and table?
	}
	
	
	@Test public void testConstruction() {
		assertTrue(m_histoTable.canGetDouble("SepalLength"));
		assertTrue(m_histoTable.canGetInt("PetalWidth"));
		assertFalse(m_histoTable.canGetDouble("Species Name"));
		assertTrue(m_histoTable.canGetString("Species Name"));
		assertTrue(50.0 == m_histoTable.getDouble(2, "Species Name count"));
	}
	
	// note that getCountMin is the min of the COUNT, not the min of
	// the DATA; what is the min/max occurrence
	@Test public void testMins() {
		assertTrue(0 == m_histoTable.getCountMin("Species Name"));
		assertTrue(0 == m_histoTable.getCountMin("SepalLength"));
		assertTrue(0 == m_histoTable.getCountMin("PetalLength"));
		assertTrue(0 == m_histoTable.getCountMin("SepalWidth"));
		assertTrue(0 == m_histoTable.getCountMin("PetalWidth"));
	}
	
	@Test public void testMaxes() {
		assertTrue(50.0 == m_histoTable.getCountMax("Species Name"));
		assertTrue(10 == m_histoTable.getCountMax("SepalLength"));
		assertTrue(26 == m_histoTable.getCountMax("SepalWidth"));
		
	}
	
    @Test public void testDataMins() {
 
        assertTrue(43 == m_histoTable.getBinMin("SepalLength"));
        assertTrue(10 == m_histoTable.getBinMin("PetalLength"));
        assertTrue(20 == m_histoTable.getBinMin("SepalWidth"));
        assertTrue(1 == m_histoTable.getBinMin("PetalWidth"));
        assertTrue(0 == m_histoTable.getBinMin("Species Name"));
}

    @Test public void testDataMaxes() {
        assertTrue(3 == m_histoTable.getBinMax("Species Name"));
        assertTrue(79 == m_histoTable.getBinMax("SepalLength"));
        assertTrue(69 == m_histoTable.getBinMax("PetalLength"));
        assertTrue(44 == m_histoTable.getBinMax("SepalWidth"));
        assertTrue(25 == m_histoTable.getBinMax("PetalWidth"));
}


}

