Skip to content

Instantly share code, notes, and snippets.

@virtix
Created October 9, 2011 11:36
Show Gist options
  • Save virtix/1273573 to your computer and use it in GitHub Desktop.
Save virtix/1273573 to your computer and use it in GitHub Desktop.
//mutation-driven
//cause an error; the program should deal with the negative number
@Test
public void testPurchasesWithNegativeNumbers(){
DiscountCalculator calc = new DiscountCalculator();
dayZero.set(2011, Calendar.JANUARY, 15, 0, 8, 45);
Account winner = a(d(-19), d(-4), p("reggae", 8, d(-12)), p("rock-a-billy", -10, d(-7)));
Discount d = calc.getSpecialDiscount(winner, d(-1));
//System.out.println( d.getDiscount() );
assertEquals("Probably should throw exception on purchases with negative amounts.", d.getDiscount().multiply(new BigDecimal(100)).intValue());
}
@Test //?? Why is the discount returning 0 when i
public void testPurchaseReggaeAndJazzEqualToTen(){
DiscountCalculator calc = new DiscountCalculator();
dayZero.set(2011, Calendar.SEPTEMBER, 15, 0, 8, 45);
Account winner = a(d(-19), d(-4), p("reggae", 6, d(-12)), p("jazz", 4, d(-7)));
Discount d = calc.getSpecialDiscount(winner, d(1));
System.out.println( d.getDiscount().multiply(new BigDecimal(100)).intValue() );
assertEquals(0, d.getDiscount().multiply(new BigDecimal(100)).intValue());
}
//this test use endDate that is before the startDate and the program should give error message
@Test
public void testEndDateBeforeStartDate(){
DiscountCalculator calc = new DiscountCalculator();
dayZero.set(2011, Calendar.SEPTEMBER, 15, 0, 8, 45);
Account winner = a(d(-19), d(-4), p("reggae", 6, d(-12)), p("jazz", 4, d(-7)));
System.out.println( calc.getDiscount(winner, d(8), d(1) ) );
assertEquals("The endDate should be after the startDdate", calc.getDiscount(winner, d(8), d(1)));
}
//this may cause the program to refactor
//the method getLoyaltyDiscount uses three parameters but the endDate seems not useful
//also new BigDecimal(discountPercentage).divide(new BigDecimal(100)) != new BigDecimal(0.15)
//also new BigDecimal(discountPercentage).divide(new BigDecimal(100)) != 0.15
//refactoring or not?
@Test
public void testEndDate(){
DiscountCalculator calc = new DiscountCalculator();
assertEquals(new BigDecimal(0.15), calc.getLoyaltyDiscount(a(d(-400), d(-400), p(100, d(-100))), d(0), d(300)).getDiscount());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment