/*
 * CapacitorTest.java
 * JUnit based test
 *
 * Created on October 12, 2003, 7:34 AM
 * @author Barry
 */

import junit.framework.*;

public class CapacitorTest extends TestCase {
    
    public CapacitorTest(java.lang.String testName) {
        super(testName);
    }
    
    public static Test suite() {
        TestSuite suite = new TestSuite(CapacitorTest.class);
        return suite;
    }
    
    /** Test of initCapacitorList method, of class Capacitor. */
    public void testInitCapacitorList() {
        System.out.println("testInitCapacitorList");
        
        // There should be all values (currently 37) in the list of capacitors
        // 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82, 100
        Capacitor[] caplist = Capacitor.initCapacitorList();
        assertEquals( Capacitor.NUMBER_CAPACITORS, caplist.length );
    }
    
    // The capacitors must be in increasing order
    public void testIncreasingOrder() {
        System.out.println("testIncreasingOrder");
        
        Capacitor[] caplist = Capacitor.initCapacitorList();
        for (int ii=0; ii<caplist.length-1; ii++)
            assertTrue( caplist[ii+1].getCapacitance() > caplist[ii].getCapacitance());
    }

    // Each capacitor must be 18% - 25% larger than the previous
    public void testHowMuchLarger() {
        System.out.println("testHowMuchLarger");
        
        Capacitor[] caplist = Capacitor.initCapacitorList();
        for (int ii=0; ii<caplist.length-1; ii++) {
            String msg = "ratio of " + (ii+1) + " and " + (ii) + " = " 
                       + (caplist[ii+1].getCapacitance()/caplist[ii].getCapacitance());
            assertTrue( msg, (caplist[ii+1].getCapacitance()/caplist[ii].getCapacitance()) > 1.18F);
            assertTrue( msg, (caplist[ii+1].getCapacitance()/caplist[ii].getCapacitance()) < 1.26F);
        }
    }
        
    // Each decade must match others
    public void testScaleByDecade() {
        System.out.println("testScaleByDecade");
        
        Capacitor[] caplist = Capacitor.initCapacitorList();
        for (int ii=0; ii<caplist.length-Capacitor.CAPACITORS_PER_DECADE; ii++) {
            double cap1 = caplist[ii].getCapacitance();
            double cap10x = caplist[ii+Capacitor.CAPACITORS_PER_DECADE].getCapacitance();
            String msg = "ratio of cap[" + ii + "] to cap[" + (ii+Capacitor.CAPACITORS_PER_DECADE) + "] is " + cap10x/cap1
                        + " but should be 10.0";
            assertTrue( msg, cap10x/cap1 == 10.0);
        }
    }
    
    // Add test methods here, they have to start with 'test' name.
    // for example:
    // public void testHello() {}
    
    
}

