import java.util.*; /** * Created by x217018 on 9/25/2015. */ public class DotcomSuiteGenerator { /** * method which recursively generates the probable testcases * @param prefix * @param lists */ public void generate(String prefix, String spacer, List<String>... lists) { int len=lists.length; if(len > 0) { List<String> list = lists[0]; lists = Arrays.copyOfRange(lists, 1, lists.length); for (String value : list) { String name = prefix + value + spacer; generate(name,spacer,lists); //recursive call if(lists.length==0) { System.out.println(name.substring(0,name.length()-1)); } } } } public static void main(String... args){ //constants String prefix="Shopping_Calendar_Matrix_Pricing_"; String spacer="_"; //parameters List<String> tripType=Arrays.asList("OW","RT","MC"); List<String> route=Arrays.asList("DOM","INTL"); List<String> paxTypeADT= Arrays.asList("ADT"); List<String> paxTypeSRC= Arrays.asList("SRC"); List<String> payType=Arrays.asList("Dollars","Points"); List<String> flightType=Arrays.asList("Dir","Conn"); List<String> fareTypeADT=Arrays.asList("BUS","ANY","WGA"); List<String> fareTypeSRC=Arrays.asList("BUSRED","ANYRED","WGARED"); List<String> scenarioType=Arrays.asList("SameMonth","DifferentMonth"); List<String> discountType=Arrays.asList("AmtDiscount","PercDiscount"); DotcomSuiteGenerator instance=new DotcomSuiteGenerator(); System.out.println("The combination of tests are: "); //generates all Adult testcases instance.generate(prefix, spacer, tripType, route, paxTypeADT, payType, flightType, fareTypeADT, scenarioType); //generates all Senior testcases instance.generate(prefix, spacer, tripType, route,paxTypeSRC,payType,flightType,fareTypeSRC,scenarioType); //generates all Adult testcases with Dollars with both Amount and Percentage Discount //instance.generate(prefix, spacer, tripType, route,paxTypeADT,Arrays.asList("Dollars"),flightType,fareTypeADT,scenarioType, discountType); //generates all Seniors testcases with Points with both Percentage Discount //instance.generate(prefix, spacer, tripType, route,paxTypeADT,Arrays.asList("Points"),flightType,fareTypeADT,scenarioType,Arrays.asList("PercDiscount")); } } //Sample data /* The combination of tests are: Shopping_Calendar_Matrix_Pricing_OW_DOM_ADT_Dollars_Dir_BUS_SameMonth Shopping_Calendar_Matrix_Pricing_OW_DOM_ADT_Dollars_Dir_BUS_DifferentMonth Shopping_Calendar_Matrix_Pricing_OW_DOM_ADT_Dollars_Dir_ANY_SameMonth Shopping_Calendar_Matrix_Pricing_OW_DOM_ADT_Dollars_Dir_ANY_DifferentMonth Shopping_Calendar_Matrix_Pricing_OW_DOM_ADT_Dollars_Dir_WGA_SameMonth Shopping_Calendar_Matrix_Pricing_OW_DOM_ADT_Dollars_Dir_WGA_DifferentMonth */
Friday, September 25, 2015
Code to generate a combination of strings recursively-Used to generate test cases from parameters
Subscribe to:
Posts (Atom)