public DiffItem Compare(ReportDataModel oldReportData) { HashSet<int> currentHash = new HashSet<int>(); HashSet<int> currentHashForExpect = new HashSet<int>(); HashSet<int> previousHash = new HashSet<int>(); Dictionary<int, Dictionary<string, BlockItem>> currentBlocks = new Dictionary<int, Dictionary<string, BlockItem>>(); Dictionary<int, Dictionary<string, BlockItem>> previousBlocks = new Dictionary<int, Dictionary<string, BlockItem>>(); foreach (string key in oldReportData.ClassMap.Keys) { if (m_classMap.ContainsKey(key) && oldReportData.ClassMap[key].HashCode == m_classMap[key].HashCode) { continue; } foreach (Item methodItem in oldReportData.ClassMap[key].Children) { foreach (Item blockItem in methodItem.Children) { BlockItem block=blockItem as BlockItem; int hash=block.HashCode; previousHash.Add(hash); if (!previousBlocks.ContainsKey(hash)) { Dictionary<string, BlockItem> previousBlockMap = new Dictionary<string, BlockItem>(); previousBlockMap.Add(block.Name, block); previousBlocks.Add(hash, previousBlockMap); } else { if (!previousBlocks[hash].ContainsKey(block.Name)) { previousBlocks[hash].Add(block.Name, block); } } } } } foreach (string key in m_classMap.Keys) { if (oldReportData.ClassMap.ContainsKey(key) && oldReportData.ClassMap[key].HashCode == m_classMap[key].HashCode) { continue; } foreach (Item methodItem in m_classMap[key].Children) { foreach (Item blockItem in methodItem.Children) { BlockItem block = blockItem as BlockItem; int hash = block.HashCode; currentHash.Add(hash); currentHashForExpect.Add(hash); if (!currentBlocks.ContainsKey(hash)) { Dictionary<string, BlockItem> currentBlockMap = new Dictionary<string, BlockItem>(); currentBlockMap.Add(block.Name, block); currentBlocks.Add(hash, currentBlockMap); } else { if (!currentBlocks[hash].ContainsKey(block.Name)) { currentBlocks[hash].Add(block.Name, block); } } } } } currentHash.ExceptWith(previousHash); previousHash.ExceptWith(currentHashForExpect); DiffItem diffItem = new DiffItem(); foreach (int i in currentHash) { foreach (BlockItem item in currentBlocks[i].Values) { diffItem.AddedBlocks.Add(item); } } foreach (int i in previousHash) { foreach (BlockItem item in previousBlocks[i].Values) { diffItem.ReducedBlocks.Add(item); } } return diffItem; }
public DiffItem CheckCoverage(DiffItem diffItem) { Predicate<BlockItem> predicate = new Predicate<BlockItem>(IsCovered); diffItem.AddedBlocks.RemoveWhere(predicate); return diffItem; }