Created
April 14, 2011 08:41
-
-
Save virtix/919133 to your computer and use it in GitHub Desktop.
Original mutation-based test generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gmu.mut.test; | |
import static org.junit.Assert.*; | |
import org.junit.Test; | |
import edu.gmu.mut.Account; | |
import edu.gmu.mut.Discount; | |
import edu.gmu.mut.GenreDiscount; | |
import edu.gmu.mut.LoyaltyDiscount; | |
import edu.gmu.mut.Purchase; | |
import java.math.BigDecimal; | |
import java.text.*; | |
import java.util.ArrayList; | |
import java.util.Calendar; | |
import java.util.GregorianCalendar; | |
public class LoyaltyDiscountTest extends BaseTest { | |
NumberFormat curFmt = NumberFormat.getCurrencyInstance(); | |
NumberFormat perFmt = NumberFormat.getPercentInstance(); | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
@Test | |
public void loyaltyDiscountShouldBeOfTypeDiscount(){ | |
//refactoring, defining new type Discount | |
Discount discount = new LoyaltyDiscount(); | |
assertEquals( "edu.gmu.mut.LoyaltyDiscount", discount.getClass().getCanonicalName() ); | |
} | |
@Test | |
public void onTheFenceUsersShouldGet10PercentOff(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 3 ); | |
ArrayList<Purchase> purchases = new ArrayList<Purchase>(); | |
Account account = Account.newInstance( "ed", "[email protected]", new GregorianCalendar(2009,Calendar.FEBRUARY,14),today, purchases ); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals( "10%" , result ); | |
} | |
@Test | |
public void usersWhoHaveSpent25To50InLastYearGet10Percent(){ | |
Purchase p = new Purchase("Coltrane", new BigDecimal(29.99), new GregorianCalendar() ); | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 3 ); | |
ArrayList<Purchase> purchases = new ArrayList<Purchase>(); | |
purchases.add(p); | |
Account account = Account.newInstance( "ed", "[email protected]", new GregorianCalendar(2009,Calendar.FEBRUARY,14),new GregorianCalendar(), purchases ); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals( "10%" , result ); | |
} | |
@Test | |
public void usersWhoHaveSpent100OrMoreInLastYearGet20Percent(){ | |
Purchase p = new Purchase("Coltrane", new BigDecimal(199.99), new GregorianCalendar(2010,Calendar.MAY,5) ); | |
ArrayList<Purchase> purchases = new ArrayList<Purchase>(); | |
purchases.add(p); | |
Account account = Account.newInstance( "ed", "[email protected]", new GregorianCalendar(2009,Calendar.FEBRUARY,14), new GregorianCalendar(), purchases ); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals( "20%" , result ); | |
} | |
@Test | |
public void newUsersWhoHaveNotMadePurchasesShouldGet15Percent(){ | |
Account account = AccountFixture.getNewAccount(); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals( "15%" , result ); | |
} | |
@Test | |
public void discountForBasicUserShouldBe10Percent(){ | |
Account account = AccountFixture.getBasicAccount(); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, new GregorianCalendar()); | |
String result = perFmt.format(amt.doubleValue()); | |
logger.info(result); | |
assertEquals( "10%" , result ); | |
} | |
@Test | |
public void fetchTotalPurchasesFromAnAccount(){ | |
Account account = AccountFixture.getBasicAccount(); | |
BigDecimal amt = LoyaltyDiscount.getTotalPurchases(account); | |
String result = curFmt.format(amt.doubleValue()) ; | |
assertEquals( "$67.86" , result ); | |
} | |
/* | |
* mutation - driven tests | |
*/ | |
/* | |
* all following tests can be generalized into one PUT with different test data | |
* the statements that contain parameters are marked with '**' | |
* @Test | |
* public void test(BigDecimal bd1){ | |
* Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
* Account account = AccountFixture.getBasicAccount(); | |
** account.getPurchaseHistory().add(new Purchase("Reggae", bd1), new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
* BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
* String result = perFmt.format(amt.doubleValue()); | |
* assertEquals(someValue, result); | |
* } | |
*/ | |
//parameters for the following tests | |
BigDecimal bd1 = new BigDecimal(99.87); | |
BigDecimal bd2 = new BigDecimal(100.99); | |
BigDecimal bd3 = new BigDecimal(24.99); | |
BigDecimal bd4 = new BigDecimal(25.99); | |
BigDecimal bd5 = new BigDecimal(49.99); | |
BigDecimal bd6 = new BigDecimal(0.99); | |
BigDecimal bd7 = new BigDecimal(50.00); | |
BigDecimal bd8 = new BigDecimal(100.00); | |
BigDecimal bd9 = new BigDecimal(25.00); | |
@Test | |
public void test8(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd1, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("10%", result); | |
}//end of the test 8 | |
@Test | |
public void test9(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd2, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("20%", result); | |
}//end of the test 9 | |
@Test | |
public void test10(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd3, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("50%", result); | |
}//end of the test 10 | |
@Test | |
public void test11(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd4, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("10%", result); | |
}//end of the test 11 | |
@Test | |
public void test12(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd5, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("10%", result); | |
}//end of the test 12 | |
@Test | |
public void test13(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd6, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("50%", result); | |
}//end of the test 13 | |
@Test | |
public void test16(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd7, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("10%", result); | |
}//end of the test 16 | |
@Test | |
//designed for ROR_16 | |
public void test18(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd8, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("20%", result); | |
}//end of the test 18 | |
@Test | |
//designed for ROR_21 | |
public void test19(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Account account = AccountFixture.getNewAccount(); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd9, new GregorianCalendar(2011, Calendar.MARCH, 5))); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("10%", result); | |
}//end of the test 19 | |
/* | |
* all following tests can be generalized into one PUT with different test data | |
* the statements that contain parameters are marked with '**' | |
* @Test | |
* public void test(BigDecimal valueOfPurchase, GregorianCalendar regDate, GregorianCalendar visitDate, GregorianCalendar purchaseDate){ | |
* Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 6 ); | |
* ArrayList purchases = new ArrayList(); | |
** Account account = Account.newInstance("new bill", "[email protected]", regDate, visitDate, purchases ); | |
** account.getPurchaseHistory().add(new Purchase("Reggae", bd1, purchaseDate)); | |
* BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
* String result = perFmt.format(amt.doubleValue()); | |
* assertEquals(someValue, result); | |
* } | |
*/ | |
Calendar today1 = new GregorianCalendar(2011, Calendar.APRIL, 6); | |
Calendar regDate1 = new GregorianCalendar(2011,Calendar.MARCH, 1); | |
Calendar regDate2 = new GregorianCalendar(2011,Calendar.MARCH, 31); | |
Calendar regDate3 = new GregorianCalendar(2011,Calendar.MARCH, 6); | |
Calendar visitDate1 = new GregorianCalendar(2011,Calendar.MARCH, 20); | |
Calendar visitDate2 = new GregorianCalendar(2011,Calendar.APRIL,2); | |
Calendar visitDate3 = new GregorianCalendar(2011,Calendar.MARCH,30); | |
GregorianCalendar purchaseDate1 = new GregorianCalendar(2010, Calendar.MARCH, 5); | |
GregorianCalendar purchaseDate2 = new GregorianCalendar(2011, Calendar.MARCH, 5); | |
ArrayList purchases = new ArrayList(); | |
BigDecimal bd10 = new BigDecimal(-2.00); | |
BigDecimal bd11 = new BigDecimal(0.00); | |
@Test | |
public void test14(){ | |
Account account = Account.newInstance("new bill", "[email protected]", regDate1, visitDate1, purchases ); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd5, purchaseDate1)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today1); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("50%", result); | |
}//end of the test 14 | |
@Test | |
//should kill COR_7, but muJava did not | |
public void test15(){ | |
ArrayList purchases = new ArrayList(); | |
Account account = Account.newInstance("new bill", "[email protected]", regDate2, visitDate1, purchases ); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd5, purchaseDate1)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today1); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("15%", result); | |
}//end of the test 15 | |
@Test | |
//designed for ROR_13 | |
public void test17(){ | |
Account account = Account.newInstance("new bill", "[email protected]", regDate3, visitDate1, purchases); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd5, purchaseDate1)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today1); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("15%", result); | |
}//end of the test 17 | |
@Test | |
//designed for ROR_30 | |
//supposed to render an error message | |
//this probably is the important test | |
public void test20(){ | |
Account account = Account.newInstance("new bill", "[email protected]", regDate1, visitDate1, purchases ); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd10, purchaseDate1)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today1); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("5%", result); | |
}//end of the test 20 | |
@Test | |
//designed for ROR_34 | |
public void test21(){ | |
Account account = Account.newInstance("new bill", "[email protected]", regDate1, visitDate2, purchases ); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd10, purchaseDate2)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today1); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("5%", result); | |
}//end of the test 21 | |
@Test | |
//designed for ROR_38 | |
public void test22(){ | |
Account account = Account.newInstance("new bill", "[email protected]", regDate1, visitDate3, purchases ); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd11, purchaseDate2)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today1); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("10%", result); | |
}//end of the test 22 | |
@Test | |
//designed for ROR_9 | |
public void test26(){ | |
Account account = Account.newInstance("new bill", "[email protected]", regDate3, visitDate2, purchases ); | |
account.getPurchaseHistory().add(new Purchase("Reggae", bd10, purchaseDate2)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today1); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals("5%", result); | |
}//end of the test 26 | |
/* | |
* all following tests can be generalized into one PUT with different test data | |
* the statements that contain parameters are marked with '**' | |
* @Test | |
* public void test(GregorianCalendar today, int days){ | |
* Account account = AccountFixture.getBasicAccount(); | |
** BigDecimal amt = LoyaltyDiscount.getTotalPurchasesBetweenNowAndNDays(account, today, 365); | |
* String result = perFmt.format(amt.doubleValue()); | |
* assertEquals(someValue, result); | |
* } | |
*/ | |
Calendar today2 = new GregorianCalendar( 2011, Calendar.APRIL, 1 ); | |
Calendar today3 = new GregorianCalendar( 2011, Calendar.APRIL, 5 ); | |
int days1 = 365; | |
int days2 = 30; | |
int days3 = 29; | |
@Test | |
public void test23(){ | |
Account account = AccountFixture.getBasicAccount(); | |
BigDecimal amt = LoyaltyDiscount.getTotalPurchasesBetweenNowAndNDays(account, today2, days1); | |
String result = curFmt.format(amt.doubleValue()); | |
assertEquals("$60.88", result); | |
}//end of the test 23 | |
@Test | |
public void test24(){ | |
Account account = AccountFixture.getBasicAccount(); | |
BigDecimal amt = LoyaltyDiscount.getTotalPurchasesBetweenNowAndNDays(account, today3, days2); | |
String result = curFmt.format(amt.doubleValue()); | |
assertEquals("$2.98", result); | |
}//end of the test 24 | |
@Test | |
public void test25(){ | |
Calendar today = new GregorianCalendar( 2011, Calendar.APRIL, 5 ); | |
Account account = AccountFixture.getBasicAccount(); | |
BigDecimal amt = LoyaltyDiscount.getTotalPurchasesBetweenNowAndNDays(account, today3, days3); | |
String result = curFmt.format(amt.doubleValue()); | |
assertEquals("$0.00", result); | |
}//end of the test 25 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gmu.mut.test; | |
import static org.junit.Assert.assertEquals; | |
import java.math.BigDecimal; | |
import java.util.Arrays; | |
import java.util.Calendar; | |
import java.util.Collection; | |
import java.util.GregorianCalendar; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.Parameterized; | |
import org.junit.runners.Parameterized.Parameters; | |
import edu.gmu.mut.Account; | |
import edu.gmu.mut.LoyaltyDiscount; | |
import edu.gmu.mut.Purchase; | |
@RunWith(Parameterized.class) | |
public class MutationGeneratedParameterizedTestsForLoyaltyTest extends BaseTest { | |
/* | |
* mutation - driven parameterized unit tests | |
*/ | |
Account account = AccountFixture.getNewAccount(); | |
static Calendar MARCH_5 = new GregorianCalendar(2011, Calendar.MARCH, 5); | |
static String genre = "Reggae"; | |
//Test data that will be initialized at test time | |
Purchase purchase = null; | |
String expectedDiscount = null; | |
public MutationGeneratedParameterizedTestsForLoyaltyTest(Purchase purchase, String expectedDiscount){ | |
this.purchase = purchase; | |
this.expectedDiscount = expectedDiscount; | |
} | |
@Parameters | |
public static Collection<Object[]> getPurchaseData(){ | |
return Arrays.asList( new Object[][] { | |
{new Purchase(genre, new BigDecimal(99.87), MARCH_5), "10%"}, | |
{new Purchase(genre, new BigDecimal(100.99), MARCH_5), "20%"}, | |
{new Purchase(genre, new BigDecimal(24.99), MARCH_5), "50%"}, | |
{new Purchase(genre, new BigDecimal(25.99), MARCH_5), "10%"}, | |
{new Purchase(genre, new BigDecimal(49.99), MARCH_5), "10%"}, | |
{new Purchase(genre, new BigDecimal(50.00), MARCH_5), "10%"}, | |
{new Purchase(genre, new BigDecimal(0.99), MARCH_5), "50%"}, | |
{new Purchase(genre, new BigDecimal(50.00), MARCH_5), "10%"}, | |
{new Purchase(genre, new BigDecimal(100.00), MARCH_5), "20%"}, | |
{new Purchase(genre, new BigDecimal(25.00), MARCH_5), "10%"} | |
}); | |
} | |
@Test | |
public void testLoyaltyDiscount(){ | |
account.getPurchaseHistory().add(this.purchase); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
String result = perFmt.format(amt.doubleValue()); | |
assertEquals(this.expectedDiscount, result); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gmu.mut.test; | |
import static org.junit.Assert.assertEquals; | |
import java.math.BigDecimal; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Calendar; | |
import java.util.Collection; | |
import java.util.GregorianCalendar; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.Parameterized; | |
import org.junit.runners.Parameterized.Parameters; | |
import edu.gmu.mut.Account; | |
import edu.gmu.mut.LoyaltyDiscount; | |
import edu.gmu.mut.Purchase; | |
/** | |
* The Class MutationGeneratedParameterizedTestsForLoyaltyCalendarTest. | |
*/ | |
@RunWith(Parameterized.class) | |
public class MutationGeneratedParameterizedTestsForLoyaltyCalendarTest extends BaseTest { | |
/** | |
* Test purchase history discount. | |
*/ | |
@Test | |
public void testPurchaseHistoryDiscount(){ | |
account.getPurchaseHistory().add(new Purchase("Reggae", this.purchaseAmt, this.purchaseDate)); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
logger.info(account.toString()); | |
String actual = perFmt.format(amt.doubleValue()); | |
assertEquals(this.expectedDiscount, actual); | |
} | |
static String genre = "Reggae"; | |
// Parameters initialized by JUnit runner | |
Calendar today; | |
Calendar regDate; | |
Calendar visitDate; | |
Calendar purchaseDate; | |
BigDecimal purchaseAmt; | |
Account account; | |
String expectedDiscount; | |
ArrayList purchases; | |
/** | |
* Instantiates a new mutation generated parameterized tests for loyalty calendar test. | |
* | |
* @param today the today | |
* @param regDate the reg date | |
* @param visitDate the visit date | |
* @param purchaseDate the purchase date | |
* @param purchaseAmt the purchase amt | |
* @param expectedDiscount the expected discount | |
*/ | |
public MutationGeneratedParameterizedTestsForLoyaltyCalendarTest(Calendar today, Calendar regDate,Calendar visitDate,Calendar purchaseDate, BigDecimal purchaseAmt, String expectedDiscount ){ | |
this.today=today; | |
this.regDate=regDate; | |
this.visitDate=visitDate; | |
this.purchaseDate=purchaseDate; | |
this.purchaseAmt=purchaseAmt; | |
this.purchases=new ArrayList(); | |
this.account = Account.newInstance("bill", "[email protected]", regDate, visitDate, this.purchases ); | |
this.expectedDiscount = expectedDiscount; | |
} | |
static Calendar MARCH_1 = new GregorianCalendar(2011,Calendar.MARCH, 1); | |
static Calendar MARCH_5 = new GregorianCalendar(2011,Calendar.MARCH, 5); | |
static Calendar MARCH_6 = new GregorianCalendar(2011,Calendar.MARCH, 6); | |
static Calendar MARCH_20 = new GregorianCalendar(2011,Calendar.MARCH, 20); | |
static Calendar MARCH_30 = new GregorianCalendar(2011,Calendar.MARCH, 30); | |
static Calendar MARCH_31 = new GregorianCalendar(2011,Calendar.MARCH, 31); | |
static Calendar APRIL_1 = new GregorianCalendar(2011,Calendar.APRIL, 1); | |
static Calendar APRIL_2 = new GregorianCalendar(2011,Calendar.APRIL, 2); | |
static Calendar APRIL_6 = new GregorianCalendar(2011,Calendar.APRIL, 6); | |
static Calendar MARCH_5_2010 = new GregorianCalendar(2010,Calendar.MARCH, 5); | |
static BigDecimal bd1 = new BigDecimal(99.87); | |
static BigDecimal bd2 = new BigDecimal(100.99); | |
static BigDecimal bd3 = new BigDecimal(24.99); | |
static BigDecimal bd4 = new BigDecimal(25.99); | |
static BigDecimal bd5 = new BigDecimal(59.99); | |
static BigDecimal bd6 = new BigDecimal(0.99); | |
static BigDecimal bd7 = new BigDecimal(50.00); | |
static BigDecimal bd8 = new BigDecimal(100.00); | |
static BigDecimal bd9 = new BigDecimal(25.00); | |
static BigDecimal bd10 = new BigDecimal(-2.00); | |
static BigDecimal bd11 = new BigDecimal(0.00); | |
/** | |
* Gets account data used to drive the test. | |
* | |
* @return the account data | |
*/ | |
@Parameters | |
public static Collection<Object[]> getAccountData(){ | |
return Arrays.asList( new Object[][] { | |
//today, regDate, visitDate, purchaseDate, purchaseAmt, expected discount | |
{APRIL_6, MARCH_1, MARCH_20, MARCH_5, bd10, "5%" }, //?? | |
{APRIL_6, MARCH_1, MARCH_20, MARCH_5, bd5, "10%" }, //test 14 | |
{APRIL_6, MARCH_31, MARCH_20, MARCH_5_2010, bd5, "15%" }, //should be exception | |
{APRIL_6, MARCH_31, MARCH_20, MARCH_5_2010, bd5, "15%" }, //should be exception | |
{APRIL_6, MARCH_1, MARCH_20, MARCH_5_2010, bd5, "50%" }, //should be exception | |
{APRIL_6, MARCH_31, MARCH_20, MARCH_5_2010, bd5, "15%" }, //test 15 COR_7 | |
{APRIL_6, MARCH_6, MARCH_20, MARCH_5_2010, bd5, "15%" }, //test 17 ROR_13 | |
{APRIL_6, MARCH_1, MARCH_20, MARCH_5_2010, bd10, "5%" }, //test 17 ROR_13 | |
{APRIL_6, MARCH_1, APRIL_2, MARCH_5, bd10, "5%" }, //test 21 ROR_34 | |
{APRIL_6, MARCH_1, MARCH_30, MARCH_5, bd11, "10%" }, //test 22 ROR_38 | |
{APRIL_6, MARCH_6, APRIL_2, MARCH_5, bd10, "5%" }, //test 22 ROR_38 | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gmu.theories; | |
import static org.junit.Assume.*; | |
import static org.junit.Assert.*; | |
import org.junit.experimental.theories.DataPoint; | |
import org.junit.experimental.theories.DataPoints; | |
import org.junit.experimental.theories.Theories; | |
import org.junit.experimental.theories.Theory; | |
import org.junit.runner.RunWith; | |
@RunWith(Theories.class) | |
public class SimpleTheory { | |
@DataPoints | |
public static int[] data = {-1,0,1,2,3,4,5}; | |
@Theory | |
public void testThis(int x, int y){ | |
assumeTrue( x > 1 && y > 1 ); | |
int result = pow(x,y); | |
System.out.println( result ); | |
assertTrue( result > 1 ); | |
} | |
//Method under test. | |
private int pow(int x, int y){ | |
return (int) Math.pow(x, y); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 | |
8 | |
16 | |
32 | |
9 | |
27 | |
81 | |
243 | |
16 | |
64 | |
256 | |
1024 | |
25 | |
125 | |
625 | |
3125 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gmu.mut.test; | |
import static org.junit.Assert.*; | |
import java.math.BigDecimal; | |
import java.util.Calendar; | |
import java.util.GregorianCalendar; | |
import org.junit.experimental.theories.DataPoint; | |
import org.junit.experimental.theories.DataPoints; | |
import org.junit.experimental.theories.Theories; | |
import org.junit.experimental.theories.Theory; | |
import org.junit.runner.RunWith; | |
import edu.gmu.mut.Account; | |
import edu.gmu.mut.LoyaltyDiscount; | |
import edu.gmu.mut.Purchase; | |
@RunWith(Theories.class) | |
public class MutationGeneratedTheoryTestsForLoyaltyTest extends BaseTest { | |
/* | |
* mutation - driven parameterized unit tests | |
*/ | |
Account account = AccountFixture.getNewAccount(); | |
static String genre = "Reggae"; | |
//Purchase Amounts | |
@DataPoint | |
public static final BigDecimal ONE_DOLLAR = new BigDecimal(1.00); | |
@DataPoint | |
public static final BigDecimal LESS_THAN_ZERO = new BigDecimal(-1.00); | |
@DataPoint | |
public static final BigDecimal ZERO = new BigDecimal(0.00); | |
@DataPoint | |
public static BigDecimal NINETY_NINE_BUCKS = new BigDecimal(99.00); | |
//Dates | |
@DataPoint | |
public static Calendar APRIL_1 = new GregorianCalendar(2011, Calendar.APRIL, 1); | |
@DataPoint | |
public static Calendar APRIL_1_2010 = new GregorianCalendar(2010, Calendar.APRIL, 1); | |
@DataPoint | |
public static Calendar APRIL_1_2020 = new GregorianCalendar(2020, Calendar.APRIL, 1); | |
@Theory | |
public void testLoyaltyDiscount(BigDecimal bd, Calendar cal){ | |
System.out.println( curFmt.format(bd) + ", " + cal.getTime().toString()); | |
Purchase purchase = new Purchase(genre, bd, cal); | |
logger.info(purchase.toString()); | |
account.getPurchaseHistory().add(purchase); | |
BigDecimal amt = LoyaltyDiscount.getDiscount(account, today); | |
double result = amt.doubleValue(); | |
assertTrue( result > 0); | |
} | |
} // | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gmu.mut.test; | |
import static org.junit.Assert.assertEquals; | |
import java.math.BigDecimal; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Calendar; | |
import java.util.Collection; | |
import java.util.GregorianCalendar; | |
import static org.junit.Assume.*; | |
import org.junit.runner.RunWith; | |
import org.junit.experimental.theories.DataPoint; | |
import org.junit.experimental.theories.Theories; | |
import org.junit.experimental.theories.Theory; | |
import static org.junit.Assert.*; | |
import edu.gmu.mut.Account; | |
import edu.gmu.mut.GenreDiscount; | |
import edu.gmu.mut.LoyaltyDiscount; | |
import edu.gmu.mut.Purchase; | |
/** | |
* The Class MutationGeneratedParameterizedTestsForLoyaltyCalendarTest. | |
*/ | |
@RunWith(Theories.class) | |
public class MutationGeneratedParameterizedTestsForGenreDiscountTest extends BaseTest { | |
//parameters for the following tests | |
@DataPoint | |
public static BigDecimal bd1 = new BigDecimal(1.00); | |
@DataPoint | |
public static BigDecimal bd2 = new BigDecimal(-10.00); | |
@DataPoint | |
public static BigDecimal bd3 = new BigDecimal(0.00); | |
@DataPoint | |
public static BigDecimal bd4 = new BigDecimal(999999999999999999999999999.9999999999999999999); | |
@DataPoint | |
public static BigDecimal bd5 = new BigDecimal(-999999999999999999999999999.9999999999999999999); | |
@DataPoint | |
public static Calendar TODAY = new GregorianCalendar(2011,Calendar.APRIL, 1); | |
@DataPoint | |
public static Calendar MARCH_1_3011 = new GregorianCalendar(3011,Calendar.MARCH, 1); | |
@DataPoint | |
public static Calendar MARCH_1_2011 = new GregorianCalendar(2011,Calendar.MARCH, 1); | |
@DataPoint | |
public static Calendar MARCH_5_2011 = new GregorianCalendar(2011,Calendar.MARCH, 5); | |
@DataPoint | |
public static Calendar MARCH_5_2010 = new GregorianCalendar(2010,Calendar.MARCH, 5); | |
public static String GENRE = "Reggae"; | |
@SuppressWarnings({ "rawtypes", "unchecked" }) //to support muJava | |
@Theory | |
public void killAllGenreDiscountMutants(Calendar regDate, Calendar visitDate, BigDecimal purchaseAmt, Calendar purchaseDate ){ | |
// assumeTrue( purchaseAmt.floatValue() > 0 ); | |
assumeTrue( regDate.before(visitDate) ); | |
assumeTrue( purchaseDate.after(regDate) ); | |
ArrayList purchases = new ArrayList(); | |
Account account = null; | |
account = Account.newInstance("new bill", "[email protected]", regDate, visitDate, purchases ); | |
account.getPurchaseHistory().add(new Purchase(GENRE, purchaseAmt, purchaseDate )); | |
String result = perFmt.format(GenreDiscount.getGenreDiscount(account, TODAY, "Classic").doubleValue()); | |
logger.info(account.getPurchaseHistory().toString()); | |
logger.info(result); | |
// assertEquals( "20%", result ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment