Skip to content

Instantly share code, notes, and snippets.

@virtix
Created March 21, 2011 19:49
Show Gist options
  • Save virtix/880074 to your computer and use it in GitHub Desktop.
Save virtix/880074 to your computer and use it in GitHub Desktop.
package edu.gmu.mut;
public class Loyalty {
/**
* Given a a number representing the total dollar amount
* of purchases, this returns some discount
* */
public Double getDiscount(Double totalPurchases) {
Double retVal = 0.0;
//between 100-1000
if(totalPurchases >= 100 && totalPurchases < 1000){
retVal = 0.10;
}
//between 1000-10000
else if (totalPurchases >= 1000 && totalPurchases < 10000){
retVal = 0.15;
}
//GT 10000
else if (totalPurchases >= 10000 ){
retVal = 0.20;
}
//GT 0
else if (totalPurchases > 0 ){
retVal = 0.05;
}
return retVal;
}
public Double getDiscountMutant_1(Double totalPurchases) {
Double retVal = 0.0;
// between 100-1000
// changed >= to >,<,==, what happens with 100?
// Obviously, it is not logical to compare exact equality
// AND any other value, as the test will either pass/fail on the first
// expression ( totalPurchases < 1000 is NOT reachable)
if(totalPurchases == 100 && totalPurchases < 1000){
retVal = 0.10;
}
//between 1000-10000
else if (totalPurchases >= 1000 && totalPurchases < 10000){
retVal = 0.15;
}
//GT 10000
else if (totalPurchases >= 10000 ){
retVal = 0.20;
}
//GT 0
else if (totalPurchases > 0 ){
retVal = 0.05;
}
return retVal;
}
}
package edu.gmu.mut;
import java.util.logging.Logger;
import junit.framework.AssertionFailedError;
import org.junit.Test;
import static org.junit.Assert.*;
public class MutantLoyaltyTest {
Logger logger = Logger.getLogger(this.getClass().getCanonicalName());
// what "data" be determined is missing?
/**
*
* Given only an input of 100.00, this test is not sensitive to
* the structural change. We need to make sure we provide data
* elements greater than 100.00 and less than 1000.00. But, how
* can we compute this?
*
* */
@Test
public void loyaltyTestShouldBeSensitiveToChanges(){
Double totalPurchases = 100.00;
Loyalty loyalty = new Loyalty();
Double actualDiscount = loyalty.getDiscountMutant_1( totalPurchases );
logger.info( actualDiscount.toString() );
assertEquals( new Double(.10), actualDiscount );
}
@Test
public void loyaltyShouldReturn10PercentForSomeCustomers(){
Double totalPurchases = 100.00;
Loyalty loyalty = new Loyalty();
Double actualDiscount = loyalty.getDiscount( totalPurchases );
logger.info( actualDiscount.toString() );
assertEquals( new Double(.10), actualDiscount );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment