public void CreateMappingTableForTestCaseFilter(TestCaseFilter filter, int targetFilterIndex, int mappingFilterIndex) { if (targetFilterIndex == -1 || mappingFilterIndex == -1) { return; } else { Dictionary <string, List <Kernel.Rule> > featureMappingTableForKernel = new Dictionary <string, List <Kernel.Rule> >(); Dictionary <string, List <Kernel.Rule> > reverseMappingTableForKernel = new Dictionary <string, List <Kernel.Rule> >(); Kernel.RuleGroup targetFilterGroup = filter[targetFilterIndex]; Kernel.RuleGroup mappingFilterGroup = filter[mappingFilterIndex]; Dictionary <string, Kernel.Rule> mappingRuleTable = CreateRuleTableFromRuleGroupForKernel(mappingFilterGroup); Dictionary <string, Kernel.Rule> targetRuleTable = CreateRuleTableFromRuleGroupForKernel(targetFilterGroup); var testCaseList = TestSuite.GetTestCases(null); foreach (TestManager.Common.TestCaseInfo testCase in testCaseList) { List <string> categories = testCase.Category.ToList(); foreach (string target in targetRuleTable.Keys) { if (categories.Contains(target)) { Kernel.Rule currentRule; foreach (string category in categories) { if (!category.Equals(target)) { mappingRuleTable.TryGetValue(category, out currentRule); if (currentRule == null) { continue; } UpdateMappingTableForKernel(featureMappingTableForKernel, target, currentRule); // Add item to reverse mapping table UpdateMappingTableForKernel(reverseMappingTableForKernel, category, targetRuleTable[target]); } } break; } } } targetFilterGroup.featureMappingTable = featureMappingTableForKernel; targetFilterGroup.mappingRuleGroup = mappingFilterGroup; mappingFilterGroup.reverseFeatureMappingTable = reverseMappingTableForKernel; mappingFilterGroup.targetRuleGroup = targetFilterGroup; } }
private Dictionary <string, Kernel.Rule> CreateRuleTableFromRuleGroupForKernel(Kernel.RuleGroup ruleGroup) { Dictionary <string, Kernel.Rule> ruleTable = new Dictionary <string, Kernel.Rule>(); Stack <Kernel.Rule> ruleStack = new Stack <Kernel.Rule>(); foreach (Kernel.Rule r in ruleGroup) { ruleStack.Push(r); } while (ruleStack.Count > 0) { Kernel.Rule r = ruleStack.Pop(); if (r.CategoryList.Count != 0 && !ruleTable.ContainsKey(r.CategoryList[0])) { ruleTable.Add(r.CategoryList[0], r); } foreach (Kernel.Rule childRule in r) { ruleStack.Push(childRule); } } return(ruleTable); }