mercredi 13 mars 2019

Junit babysiter kata

I'm having a bit of trouble running test for the babysitter kata on java/junit. My test keeps telling me that the expected was 16 but it was actually 60. I don't know where my math is going wrong to get this output. I would like for my expected to match my actual for my second test.

public Object calculatePay() {
        int potentialPayBefore10 = 12;
        int potentialPayAfter10 = 8;

        // $12 hour * 5 hours worked
        potentialPayBefore10 = 12 * 5;
        potentialPayAfter10 = 8 * 2;

        // TODO Auto-generated method stub

        if (potentialPayBefore10 < 60) {
            return potentialPayAfter10;
        } else
            return potentialPayBefore10;

    }

}


public class DaysWorked {

    /*
     * Story: As a babysitter In order to get paid for 1 night of work I want to
     * calculate my nightly charge
     */

    // Project Goal: Create test to show Mellie being paid

    // Start with calc time for 1 hour of work
    @Test
    public void calculatepayforworkafterstarttimeat12hourly() {
        // 5 is hours worked if start at 5 pm til 10p
        MellieWageCalculator potentialPay = new MellieWageCalculator(5);
        // assert equals gives -> (expected, actual)
        assertEquals(60, potentialPay.calculatePay());
    }

    @Test
    public void calculatepayforworkafter10pmat8hourly() {
        // 2 hours worked if start at 10pm til 12 pm
        MellieWageCalculator potentialPay = new MellieWageCalculator(2);
        assertEquals(16, potentialPay.calculatePay());

    }

}

Aucun commentaire:

Enregistrer un commentaire