예제 #1
0
        static int calculateScore(Configuration input, int order)
        {
            int result = 0;

            List<string> failCoveringOptions = TESTCASE_LIST[order].getCoveringListOptions();
            List<Item> focusedItemList = getOptionsWithTheseNames(input, failCoveringOptions);

            List<List<Item>> subset = getSubsetOptions(focusedItemList);

            for (int subsetOrder = 0; subsetOrder < subset.Count; subsetOrder++)
            {
                if (!doWeHaveThisConfiguration(subset[subsetOrder], order))
                    result++;
            }

            return result;
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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();
        }
예제 #5
0
        static List<Item> getOptionsWithTheseNames(Configuration param1, List<string> names)
        {
            List<Item> result = new List<Item>();
            List<Item> itemList = param1.getItemList();

            for (int a = 0; a < names.Count; a++)
            {
                string nameToCheck = names[a];

                for (int b = 0; b < itemList.Count; b++)
                {
                    if (itemList[b].getObjectName() == nameToCheck)
                    {
                        Item temp = new Item();
                        temp.setEqualTo(itemList[b]);
                        result.Add(temp);
                    }
                }
            }
            return result;
        }
예제 #6
0
 public void setEqualTo(Configuration rhs)
 {
     setResult(rhs.getResult());
     setItemList(rhs.getItemList());
 }
예제 #7
0
 public Configuration getChangedConf()
 {
     Configuration result = new Configuration();
     result.setEqualTo(changed);
     return result;
 }
예제 #8
0
        //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;
        }
예제 #9
0
 public Triplet()
 {
     original = new Configuration();
     changed = new Configuration();
     score = 0;
 }
예제 #10
0
        public Triplet(Configuration orig, Configuration chan, int sco)
        {
            original = new Configuration();
            original.setEqualTo(orig);

            changed = new Configuration();
            changed.setEqualTo(chan);

            score = sco;
        }
예제 #11
0
        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);
            }
        }
예제 #12
0
        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;
        }
예제 #13
0
        public void addNewConfiguration(Configuration param1)
        {
            Configuration temp = new Configuration();
            temp.setEqualTo(param1);

            AddedList.Add(temp);
        }
예제 #14
0
        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;
                            }
                        }
                    }
                }
            }
        }
예제 #15
0
 public Configuration getOriginalConf()
 {
     Configuration result = new Configuration();
     result.setEqualTo(original);
     return result;
 }
예제 #16
0
        //given a changed configuration, check if that configuration was in TRIPLE_LIST before
        static bool doesExistInScoreList(Configuration input)
        {
            for (int counter = 0; counter < TRIPLET_LIST.Count; counter++)
            {
                bool exists = true;

                Triplet tempTrip = new Triplet();
                tempTrip.setEqualTo(TRIPLET_LIST[counter]);

                List<Item> tripOptionList = tempTrip.getChangedConf().getItemList();
                List<Item> inputOptionList = input.getItemList();

                for (int a = 0; a < inputOptionList.Count; a++)
                {
                    if (!doesExist(tripOptionList, inputOptionList[a]))
                        exists = false;
                }

                if (exists)
                    return true;
            }
            return false;
        }
예제 #17
0
 public void setChangedConf(Configuration param1)
 {
     changed.setEqualTo(param1);
 }
예제 #18
0
        //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;
        }
예제 #19
0
 public void setOriginalConf(Configuration param1)
 {
     original.setEqualTo(param1);
 }
예제 #20
0
        //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;
        }
예제 #21
0
        //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;
        }
예제 #22
0
        //Parses configuration file, which contains information about configurations that have been tested and their results
        //Passing configuration's result is "p", otherwise that configuration is counted as failing configuration
        //It is assumed that a configuration consists of all options previously parsed
        static void parseConfigurationsXML(string filename)
        {
            FileStream reader = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            XmlDocument compSpecs = new XmlDocument();
            compSpecs.Load(reader);

            XmlNodeList nodeList = compSpecs.GetElementsByTagName("test");

            for (int counter = 0; counter < nodeList.Count; counter++)
            {
                Testcase testcaseToAdd = new Testcase();

                XmlNode currentTestNode = nodeList[counter];

                //set test id
                string testId = currentTestNode.Attributes[0].Value;
                testcaseToAdd.setId(testId);

                List<Configuration> passList = new List<Configuration>();
                List<Configuration> failList = new List<Configuration>();

                //get children nodes, which are configuration nodes
                XmlNodeList childNodes = nodeList[counter].ChildNodes;
                for (int a = 0; a < childNodes.Count; a++)
                {
                    XmlNode configNode = childNodes[a];

                    //get configuration result
                    string configResult = configNode.Attributes[0].Value;

                    List<Item> optionList = new List<Item>();

                    //get children nodes, which are option nodes
                    XmlNodeList optionNodes = configNode.ChildNodes;
                    for (int b = 0; b < optionNodes.Count; b++)
                    {
                        string optionName = optionNodes[b].Attributes[0].Value;
                        string optionValue = optionNodes[b].InnerText;

                        Item dummy = new Item(optionName, optionValue);
                        optionList.Add(dummy);
                    }

                    optionList.Sort(delegate(Item aa, Item bb) { return aa.getObjectName().CompareTo(bb.getObjectName()); });

                    Configuration toAdd = new Configuration(configResult, optionList);

                    if (configResult == "p")
                        passList.Add(toAdd);
                    else
                        failList.Add(toAdd);
                }

                testcaseToAdd.setPassingList(passList);
                testcaseToAdd.setFailingList(failList);

                TESTCASE_LIST.Add(testcaseToAdd);
            }

            reader.Close();
        }
예제 #23
0
        static void print(Configuration param1)
        {
            string result = param1.getResult();
            List<Item> options = param1.getItemList();

            Console.Write("result=" + result + " ");

            for (int a = 0; a < options.Count; a++)
                Console.Write(options[a].getObjectName() + "=" + options[a].getObjectValue() + " ");

            Console.Write("\n");
        }