/*
 * TimeSim1Test.java
 * JUnit based test
 *
 * Created on October 12, 2003, 10:13 PM
 */

import javax.swing.table.*;
import junit.framework.*;

/**
 *
 * @author Barry
 */
public class TimeSim1Test extends TestCase {
    
    public TimeSim1Test(java.lang.String testName) {
        super(testName);
    }
    
    public static Test suite() {
        TestSuite suite = new TestSuite(TimeSim1Test.class);
        return suite;
    }
    
    /** Test of getAppletInfo method, of class TimeSim1. */
    public void testGetAppletInfo() {
        System.out.println("testGetAppletInfo");
        
        // must return a non-empty string
        TimeSim1 t = new TimeSim1();
        String sInfo = t.getAppletInfo();
        assertNotNull(sInfo);
        assertTrue(sInfo != "");
    }
    
    /** Test of init method, of class TimeSim1. */
    public void testInit() {
        System.out.println("testInit");
        // unable to test this method?
    }
    
    /** Test of initColumnTime method, of class TimeSim1. */
    public void testInitColumnTime() {
        System.out.println("testInitColumnTime");
        TimeSim1 t = new TimeSim1();
        
        // Generate time[] and verify results
        double[] time = t.initColumnTime(1E-3,1E-3);
        assertEquals(t.TIME_COLUMNS, time.length);
        
        System.out.println("   " + time[0] + ", " + time[1] + ", " + time[2]
                          + ", " + time[3] + ", " + time[4] + ", " + time[5]
                          + ", " + time[6] + ", " + time[7] + ", " + time[8]
                          + ", " + time[9]);
        assertTrue(0.001 == time[0]);   // first element
        assertTrue(0.002 == time[1]);   // second element
        assertTrue(0.003 == time[2]);   // third element
        
        // repeat test at a different time scale
        time = t.initColumnTime(1E-4,1E-4);
        assertTrue(0.0001 == time[0]);
        assertTrue(0.0002 == time[1]);
    }
    
    /** Test of computeInductance method, of class TimeSim1. */
    public void testComputeInductance() {
        System.out.println("testComputeInductance");
    }
    
    /** Test of initColumnNames method, of class TimeSim1. */
    public void testInitColumnNames() {
        System.out.println("testInitColumnNames");
        TimeSim1 t = new TimeSim1();
        
        t.init();       // create everything (so we can test it)
        
        // test the start-up column names
        String[] sCol = t.initColumnNames();
        assertEquals("Cap", sCol[0]);
        assertEquals("1.0 ms", sCol[1]);
        assertEquals("2.0 ms", sCol[2]);
        assertEquals("10 ms", sCol[10]);

        // scroll left and repeat test
        t.time = t.initColumnTime(1E-4, 1E-4);
        sCol = t.initColumnNames();
        assertEquals("Cap", sCol[0]);
        assertEquals("100 us", sCol[1]);
        assertEquals("200 us", sCol[2]);
        assertEquals("1.0 ms", sCol[10]);
    }
    
    /** Test of initInductanceTable method, of class TimeSim1. */
    public void testInitInductanceTable() {
        System.out.println("testInitInductanceTable");
        TimeSim1 t = new TimeSim1();
        t.init();       // create everything (so we can test it)
        
        t.initInductanceTable();
        
        // verify upper left corner (1 second and 1 farad)
        String expected_L = "101 mh";
        //String computed_L = jTable.getValueAt(0, 0); // how-to access 'private jTable'?
        //assertEquals( expected_L, computed_L);
        
        // verify a typical coilgun value (10msec and 10,000 uF)
        expected_L = "101 mh";
        //String computed_L = jTable.getValueAt(10, 9); // how-to access 'private jTable'?
        //assertEquals( expected_L, computed_L);
    }
    
    /** Test of initRowNames method, of class TimeSim1. */
    public void testInitRowNames() {
        System.out.println("testInitRowNames");
    }
    
    /** Test of computeCustom method */
    public void testComputeCustom() {
        System.out.println("testComputeCustom");
        TimeSim1 t = new TimeSim1();
        t.init();       // create everything (so we can test it)
        
        assertEquals("10.1 uH", t.computeCustom("1000", "10000")); // note units are usec, uF
        assertEquals("101 uH",  t.computeCustom("1000", "1000"));
        assertEquals("101 nH", t.computeCustom("1.0", "1.0"));
        assertEquals("101 uH", t.computeCustom("1E3", "1E3"));
        
        assertEquals("not a number", t.computeCustom("bogus", "1"));
        assertEquals("not a number", t.computeCustom("1", "bogus"));
        assertEquals("not a number", t.computeCustom("1a", "1b"));
    }
    
    // Add test methods here, they have to start with 'test' name.
    // for example:
    // public void testHello() {}
    
    
}

