//returns the option list of the rule, that configuration is violating static List<Item> getRuleViolatingOptions(Configuration input, int order) { Configuration testingConfig = new Configuration(); testingConfig.setEqualTo(input); List<Item> optionsList = testingConfig.getItemList(); for (int counter = 0; counter < TESTCASE_LIST[order].getRuleList().Count; counter++) { Rule tempRule = new Rule(); tempRule.setEqualTo(TESTCASE_LIST[order].getRuleList()[counter]); List<Item> ruleOptionList = tempRule.getItemList(); bool thereIsError = true; for (int a = 0; a < ruleOptionList.Count; a++) { string optionName = ruleOptionList[a].getObjectName(); string optionValue = ruleOptionList[a].getObjectValue(); Item dummy = new Item(optionName, optionValue); if (!doesExist(optionsList, dummy)) { thereIsError = false; break; } } if (thereIsError) { List<Item> result = new List<Item>(); for (int a = 0; a < ruleOptionList.Count; a++) result.Add(ruleOptionList[a]); return result; } } return null; }
//Given a configuration, checks if this configuration passes based on the rule list static bool doesThisConfigPass(Configuration param1, int order) { Configuration testingConfig = new Configuration(); testingConfig.setEqualTo(param1); List<Item> optionsList = testingConfig.getItemList(); for (int counter = 0; counter < TESTCASE_LIST[order].getRuleList().Count; counter++) { Rule tempRule = new Rule(); tempRule.setEqualTo(TESTCASE_LIST[order].getRuleList()[counter]); List<Item> ruleOptionList = tempRule.getItemList(); bool thereIsError = true; for (int a = 0; a < ruleOptionList.Count; a++) { string optionName = ruleOptionList[a].getObjectName(); string optionValue = ruleOptionList[a].getObjectValue(); Item dummy = new Item(optionName, optionValue); if (!doesExist(optionsList, dummy)) { thereIsError = false; break; } } if (thereIsError) return false; } return true; }
//checks if the items in input list exists in any passing configuration static bool doWeHaveThisConfiguration(List<Item> input, int order) { for (int counter = 0; counter < TESTCASE_LIST[order].getPassingList().Count; counter++) { Configuration passConf = new Configuration(); passConf.setEqualTo(TESTCASE_LIST[order].getPassingList()[counter]); List<Item> passOptions = passConf.getItemList(); bool exists = true; for (int a = 0; a < input.Count; a++) { if (!doesExist(passOptions, input[a])) exists = false; } if (exists) return true; } for (int counter = 0; counter < TESTCASE_LIST[order].getAddedList().Count; counter++) { Configuration passConf = new Configuration(); passConf.setEqualTo(TESTCASE_LIST[order].getAddedList()[counter]); List<Item> passOptions = passConf.getItemList(); bool exists = true; for (int a = 0; a < input.Count; a++) { if (!doesExist(passOptions, input[a])) exists = false; } if (exists) return true; } return false; }
static void daErdalAlgorithm() { for (int TestOrder = 0; TestOrder < TESTCASE_LIST.Count; TestOrder++) { for (int orderOfFailingConfig = 0; orderOfFailingConfig < TESTCASE_LIST[TestOrder].getFailingList().Count; orderOfFailingConfig++) { Configuration originalFailingConfig = new Configuration(); originalFailingConfig.setEqualTo(TESTCASE_LIST[TestOrder].getFailingList()[orderOfFailingConfig]); List<Item> ruleViolatingOptions = getRuleViolatingOptions(originalFailingConfig,TestOrder); if (ruleViolatingOptions != null) { List<List<string>> subsetOfFailingOptions = getSubset(ruleViolatingOptions); for (int subsetOrder = 0; subsetOrder < subsetOfFailingOptions.Count; subsetOrder++) { List<List<Item>> changeList = getTruthTable(subsetOfFailingOptions[subsetOrder]); for (int changeOrder = 0; changeOrder < changeList.Count; changeOrder++) { Configuration changedConfig = applyChange(originalFailingConfig, changeList[changeOrder]); bool configPasses = doesThisConfigPass(changedConfig, TestOrder); if (configPasses) { if (!doesExistInScoreList(changedConfig)) { int score = calculateScore(changedConfig, TestOrder); if (score > 0) { Triplet tr = new Triplet(originalFailingConfig, changedConfig, score); TRIPLET_LIST.Add(tr); } } } } } } TRIPLET_LIST.Sort(delegate(Triplet a, Triplet b) { return a.getScore().CompareTo(b.getScore()); }); if (TRIPLET_LIST.Count > 0) { Configuration toAdd = new Configuration(); toAdd.setEqualTo(TRIPLET_LIST[TRIPLET_LIST.Count - 1].getChangedConf()); Configuration orig = new Configuration(); orig.setEqualTo(TRIPLET_LIST[TRIPLET_LIST.Count - 1].getOriginalConf()); toAdd.setResult("p"); TESTCASE_LIST[TestOrder].addNewConfiguration(toAdd); Console.Write("**old**\t"); print(orig); Console.Write("**new**\t"); print(toAdd); Console.Write("\n"); TRIPLET_LIST.RemoveAt(TRIPLET_LIST.Count - 1); if (CHOOSE_GLOBAL) { updateTripletList(TestOrder); } else { TRIPLET_LIST.Clear(); } } } TRIPLET_LIST.Clear(); } }
static void daErmanAlgorithm() { for (int TestOrder = 0; TestOrder < TESTCASE_LIST.Count; TestOrder++) { for (int orderOfFailingConfig = 0; orderOfFailingConfig < TESTCASE_LIST[TestOrder].getFailingList().Count; orderOfFailingConfig++) { Configuration originalFailingConfiguration = new Configuration(); originalFailingConfiguration.setEqualTo(TESTCASE_LIST[TestOrder].getFailingList()[orderOfFailingConfig]); bool passingConfigFound = false; List<Item> ruleViolatingOptions = getRuleViolatingOptions(originalFailingConfiguration, TestOrder); List<List<string>> subsetOfFailingOptions = getSubset(ruleViolatingOptions); for (int subsetOrder = 0; (subsetOrder < subsetOfFailingOptions.Count) && !passingConfigFound; subsetOrder++) { List<List<Item>> changeList = getTruthTable(subsetOfFailingOptions[subsetOrder]); for (int changeOrder = 0; changeOrder < changeList.Count; changeOrder++) { Configuration changedConfig = applyChange(originalFailingConfiguration, changeList[changeOrder]); bool configPasses = doesThisConfigPass(changedConfig, TestOrder); if (configPasses) { changedConfig.setResult("p"); TESTCASE_LIST[TestOrder].addNewConfiguration(changedConfig); Console.Write("**old**\t"); print(originalFailingConfiguration); Console.Write("**new**\t"); print(changedConfig); Console.Write("\n"); passingConfigFound = true; break; } } } } } }
//given an initial config and a list of changes, apply each change to the configuration //originalConfig = [a=0, b=1, c=0] and changeList = [a=1,b=0] //result = [a=1, b=0, c=0] static Configuration applyChange(Configuration originalConfig, List<Item> changeList) { Configuration result = new Configuration(); result.setEqualTo(originalConfig); for (int a = 0; a < changeList.Count; a++) { result.changeItemValue(changeList[a].getObjectName(), changeList[a].getObjectValue()); } return result; }
static void calculateAlgorithmScore() { TextWriter tw = new StreamWriter("Score.txt"); for (int TestOrder = 0; TestOrder < TESTCASE_LIST.Count; TestOrder++) { List<List<Item>> totalSubset = new List<List<Item>>(); for (int count = 0; count < TESTCASE_LIST[TestOrder].getAddedList().Count; count++) { Configuration tempCof = new Configuration(); tempCof.setEqualTo(TESTCASE_LIST[TestOrder].getAddedList()[count]); List<string> failureCoveringOptions = TESTCASE_LIST[TestOrder].getCoveringListOptions(); List<Item> focusedOptionList = getOptionsWithTheseNames(tempCof, failureCoveringOptions); combineSet(totalSubset, getSubsetOptions(focusedOptionList)); } for (int count2 = 0; count2 < TESTCASE_LIST[TestOrder].getPassingList().Count; count2++) { Configuration tempCof2 = new Configuration(); tempCof2.setEqualTo(TESTCASE_LIST[TestOrder].getPassingList()[count2]); List<string> failureCoveringOptions2 = TESTCASE_LIST[TestOrder].getCoveringListOptions(); List<Item> focusedOptionList2 = getOptionsWithTheseNames(tempCof2, failureCoveringOptions2); subtractSet(totalSubset, getSubsetOptions(focusedOptionList2)); } totalSubset.Sort(delegate(List<Item> a, List<Item> b) { return a.Count.CompareTo(b.Count); }); TESTCASE_LIST[TestOrder].setScore(totalSubset.Count); tw.WriteLine("Test_ID= " + TESTCASE_LIST[TestOrder].getId() + "\t" + "Number of new configurations=" + TESTCASE_LIST[TestOrder].getAddedList().Count + "\t" + "Number of new combinations found=" + TESTCASE_LIST[TestOrder].getScore()); } tw.Close(); }
public Configuration getChangedConf() { Configuration result = new Configuration(); result.setEqualTo(changed); return result; }
public Configuration getOriginalConf() { Configuration result = new Configuration(); result.setEqualTo(original); return result; }
public Triplet(Configuration orig, Configuration chan, int sco) { original = new Configuration(); original.setEqualTo(orig); changed = new Configuration(); changed.setEqualTo(chan); score = sco; }
public void setPassingList(List<Configuration> param1) { PassingList.Clear(); for (int a = 0; a < param1.Count; a++) { Configuration temp = new Configuration(); temp.setEqualTo(param1[a]); PassingList.Add(temp); } }
public List<Configuration> getPassingList() { List<Configuration> result = new List<Configuration>(); for (int a = 0; a < PassingList.Count; a++) { Configuration temp = new Configuration(); temp.setEqualTo(PassingList[a]); result.Add(temp); } return result; }
public void addNewConfiguration(Configuration param1) { Configuration temp = new Configuration(); temp.setEqualTo(param1); AddedList.Add(temp); }
static void updateTripletList(int order) { for (int counter = 0; counter < TRIPLET_LIST.Count; counter++) { Configuration temp = new Configuration(); temp.setEqualTo(TRIPLET_LIST[counter].getChangedConf()); int score = calculateScore(temp, order); TRIPLET_LIST[counter].setScore(score); } }