package hws.hw2;

/**
 * A driver that can be used to test the Pricer class.
 *
 * @author CS159 Faculty
 * @version f25
 */
public class ItemPricerTest {

    /**
     * The entry point of the driver.
     *
     * @param args The command-line arguments (which are ignored)
     */
    public static void main(String[] args) {

        final double tolerance = 0.01;
        String description;
        ItemPricer largePricer, smallPricer;

        System.out.println("Tests that were Failed:");

        // Tests for smalls

        smallPricer = new ItemPricer(12, 9.99, 0.99);
        int[] smalls = {-30, 0, 5, 7, 12, 13, 23, 36, 98};

        System.out.println("");
        int[] expectedFullBoxes = {0, 0, 0, 0, 1, 1, 1, 3, 8};
        for (int i = 0; i < smalls.length; i++) {
            description = String.format("smallPricer.numberOfFullBoxes(%d)", smalls[i]);
            EqualityChecker.forEqualInts(expectedFullBoxes[i], smallPricer.numberOfFullBoxes(smalls[i]), description);
        }

        System.out.println("");
        int[] expectedExtras = {0, 0, 5, 7, 0, 1, 11, 0, 2};
        for (int i = 0; i < smalls.length; i++) {
            description = String.format("smallPricer.numberOfExtras(%d)", smalls[i]);
            EqualityChecker.forEqualInts(expectedExtras[i], smallPricer.numberOfExtras(smalls[i]), description);
        }

        System.out.println("");
        boolean[] expectedNeedExtra = {false, false, true, true, false, true, true, false, true};
        for (int i = 0; i < smalls.length; i++) {
            description = String.format("smallPricer.needAnExtraBox(%d)", smalls[i]);
            if (expectedNeedExtra[i])
                EqualityChecker.forTrue(smallPricer.needAnExtraBox(smalls[i]), description);
            else
                EqualityChecker.forFalse(smallPricer.needAnExtraBox(smalls[i]), description);
        }

        System.out.println("");
        int[] expectedBoxes = {0, 0, 1, 1, 1, 2, 2, 3, 9};
        for (int i = 0; i < smalls.length; i++) {
            description = String.format("smallPricer.numberOfBoxes(%d)", smalls[i]);
            EqualityChecker.forEqualInts(expectedBoxes[i], smallPricer.numberOfBoxes(smalls[i]), description);
        }

        System.out.println("");
        double[] expectedPrice = {0.00, 0.00, 4.95, 6.93, 9.99, 10.98, 20.88, 29.97, 81.90};
        for (int i = 0; i < smalls.length; i++) {
            description = String.format("smallPricer.priceFor(%d)", smalls[i]);
            EqualityChecker.forEqualDoubles(expectedPrice[i], smallPricer.priceFor(smalls[i]), tolerance, description);
        }

        // Tests for larges

        largePricer = new ItemPricer(36, 17.99, 0.75);
        int[] larges = {-80, 0, 15, 36, 150};

        System.out.println("");
        double[] expectedLargePrice = {0.00, 0.00, 11.25, 17.99, 76.46};
        for (int i = 0; i < larges.length; i++) {
            description = String.format("largePricer.priceFor(%d)", larges[i]);
            EqualityChecker.forEqualDoubles(expectedLargePrice[i], largePricer.priceFor(larges[i]), tolerance, description);
        }

        // Re-test for smalls (just in case)

        System.out.println("");
        for (int i = 0; i < smalls.length; i++) {
            description = String.format( "After testing largePricer - smallPricer.priceFor(%d)", smalls[i]);
            EqualityChecker.forEqualDoubles(expectedPrice[i], smallPricer.priceFor(smalls[i]), tolerance, description);
        }

    }

}
