Exemplo n.º 1
0
        /// <summary>
        /// Merges the two tracked method coverage.
        /// </summary>
        /// <param name="existingTrackedMethodCoverage">The existing tracked method coverage.</param>
        /// <param name="lineCoverageByTestMethod">The new line coverage by test method.</param>
        /// <returns>The merged tracked method coverage.</returns>
        private static CoverageByTrackedMethod MergeCoverageByTrackedMetho(CoverageByTrackedMethod existingTrackedMethodCoverage, CoverageByTrackedMethod lineCoverageByTestMethod)
        {
            // Resize coverage array if neccessary
            if (lineCoverageByTestMethod.Coverage.LongLength > existingTrackedMethodCoverage.Coverage.LongLength)
            {
                int[] newLineCoverage = new int[lineCoverageByTestMethod.Coverage.LongLength];

                Array.Copy(lineCoverageByTestMethod.Coverage, newLineCoverage, lineCoverageByTestMethod.Coverage.LongLength);

                for (long i = existingTrackedMethodCoverage.Coverage.LongLength; i < lineCoverageByTestMethod.Coverage.LongLength; i++)
                {
                    newLineCoverage[i] = -1;
                }

                existingTrackedMethodCoverage.Coverage = newLineCoverage;
            }

            // Resize line visit status array if neccessary
            if (lineCoverageByTestMethod.LineVisitStatus.LongLength > existingTrackedMethodCoverage.LineVisitStatus.LongLength)
            {
                LineVisitStatus[] newLineVisitStatus = new LineVisitStatus[lineCoverageByTestMethod.LineVisitStatus.LongLength];
                Array.Copy(lineCoverageByTestMethod.LineVisitStatus, newLineVisitStatus, lineCoverageByTestMethod.LineVisitStatus.LongLength);
                existingTrackedMethodCoverage.LineVisitStatus = newLineVisitStatus;
            }

            for (long i = 0; i < lineCoverageByTestMethod.Coverage.LongLength; i++)
            {
                int coverage = existingTrackedMethodCoverage.Coverage[i];

                if (coverage < 0)
                {
                    coverage = lineCoverageByTestMethod.Coverage[i];
                }
                else if (lineCoverageByTestMethod.Coverage[i] > 0)
                {
                    coverage += lineCoverageByTestMethod.Coverage[i];
                }

                existingTrackedMethodCoverage.Coverage[i] = coverage;
            }

            for (long i = 0; i < lineCoverageByTestMethod.LineVisitStatus.LongLength; i++)
            {
                int lineVisitStatus = Math.Max((int)existingTrackedMethodCoverage.LineVisitStatus[i], (int)lineCoverageByTestMethod.LineVisitStatus[i]);

                existingTrackedMethodCoverage.LineVisitStatus[i] = (LineVisitStatus)lineVisitStatus;
            }

            return(existingTrackedMethodCoverage);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the coverage by test method.
        /// </summary>
        /// <param name="testMethod">The test method.</param>
        /// <param name="trackedMethodCoverage">The coverage by for test method.</param>
        internal void AddCoverageByTestMethod(TestMethod testMethod, CoverageByTrackedMethod trackedMethodCoverage)
        {
            if (testMethod == null)
            {
                throw new ArgumentNullException(nameof(testMethod));
            }

            if (trackedMethodCoverage == null)
            {
                throw new ArgumentNullException(nameof(trackedMethodCoverage));
            }

            this.lineCoveragesByTestMethod.Add(testMethod, trackedMethodCoverage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the coverage by test method.
        /// </summary>
        /// <param name="testMethod">The test method.</param>
        /// <param name="trackedMethodCoverage">The coverage by for test method.</param>
        internal void AddCoverageByTestMethod(TestMethod testMethod, CoverageByTrackedMethod trackedMethodCoverage)
        {
            if (testMethod == null)
            {
                throw new ArgumentNullException(nameof(testMethod));
            }

            if (trackedMethodCoverage == null)
            {
                throw new ArgumentNullException(nameof(trackedMethodCoverage));
            }

            CoverageByTrackedMethod existingTrackedMethodCoverage;

            if (!this.lineCoveragesByTestMethod.TryGetValue(testMethod, out existingTrackedMethodCoverage))
            {
                this.lineCoveragesByTestMethod.Add(testMethod, trackedMethodCoverage);
            }
            else
            {
                this.lineCoveragesByTestMethod[testMethod] = MergeCoverageByTrackedMetho(existingTrackedMethodCoverage, trackedMethodCoverage);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Merges the given file with the current instance.
        /// </summary>
        /// <param name="file">The file to merge.</param>
        internal void Merge(CodeFile file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            // Resize coverage array if neccessary
            if (file.lineCoverage.LongLength > this.lineCoverage.LongLength)
            {
                int[] newLineCoverage = new int[file.lineCoverage.LongLength];

                Array.Copy(this.lineCoverage, newLineCoverage, this.lineCoverage.LongLength);

                for (long i = this.lineCoverage.LongLength; i < file.lineCoverage.LongLength; i++)
                {
                    newLineCoverage[i] = -1;
                }

                this.lineCoverage = newLineCoverage;
            }

            // Resize line visit status array if neccessary
            if (file.lineVisitStatus.LongLength > this.lineVisitStatus.LongLength)
            {
                LineVisitStatus[] newLineVisitStatus = new LineVisitStatus[file.lineVisitStatus.LongLength];
                Array.Copy(this.lineVisitStatus, newLineVisitStatus, this.lineVisitStatus.LongLength);
                this.lineVisitStatus = newLineVisitStatus;
            }

            for (long i = 0; i < file.lineCoverage.LongLength; i++)
            {
                int coverage = this.lineCoverage[i];

                if (coverage < 0)
                {
                    coverage = file.lineCoverage[i];
                }
                else if (file.lineCoverage[i] > 0)
                {
                    coverage += file.lineCoverage[i];
                }

                this.lineCoverage[i] = coverage;
            }

            for (long i = 0; i < file.lineVisitStatus.LongLength; i++)
            {
                int lineVisitStatus = Math.Max((int)this.lineVisitStatus[i], (int)file.lineVisitStatus[i]);

                this.lineVisitStatus[i] = (LineVisitStatus)lineVisitStatus;
            }

            foreach (var lineCoverageByTestMethod in file.lineCoveragesByTestMethod)
            {
                CoverageByTrackedMethod existingTrackedMethodCoverage = null;

                this.lineCoveragesByTestMethod.TryGetValue(lineCoverageByTestMethod.Key, out existingTrackedMethodCoverage);

                if (existingTrackedMethodCoverage == null)
                {
                    this.lineCoveragesByTestMethod.Add(lineCoverageByTestMethod);
                }
                else
                {
                    // Resize coverage array if neccessary
                    if (lineCoverageByTestMethod.Value.Coverage.LongLength > existingTrackedMethodCoverage.Coverage.LongLength)
                    {
                        int[] newLineCoverage = new int[lineCoverageByTestMethod.Value.Coverage.LongLength];

                        Array.Copy(lineCoverageByTestMethod.Value.Coverage, newLineCoverage, lineCoverageByTestMethod.Value.Coverage.LongLength);

                        for (long i = existingTrackedMethodCoverage.Coverage.LongLength; i < lineCoverageByTestMethod.Value.Coverage.LongLength; i++)
                        {
                            newLineCoverage[i] = -1;
                        }

                        existingTrackedMethodCoverage.Coverage = newLineCoverage;
                    }

                    // Resize line visit status array if neccessary
                    if (lineCoverageByTestMethod.Value.LineVisitStatus.LongLength > existingTrackedMethodCoverage.LineVisitStatus.LongLength)
                    {
                        LineVisitStatus[] newLineVisitStatus = new LineVisitStatus[lineCoverageByTestMethod.Value.LineVisitStatus.LongLength];
                        Array.Copy(lineCoverageByTestMethod.Value.LineVisitStatus, newLineVisitStatus, lineCoverageByTestMethod.Value.LineVisitStatus.LongLength);
                        existingTrackedMethodCoverage.LineVisitStatus = newLineVisitStatus;
                    }

                    for (long i = 0; i < lineCoverageByTestMethod.Value.Coverage.LongLength; i++)
                    {
                        int coverage = existingTrackedMethodCoverage.Coverage[i];

                        if (coverage < 0)
                        {
                            coverage = lineCoverageByTestMethod.Value.Coverage[i];
                        }
                        else if (lineCoverageByTestMethod.Value.Coverage[i] > 0)
                        {
                            coverage += lineCoverageByTestMethod.Value.Coverage[i];
                        }

                        existingTrackedMethodCoverage.Coverage[i] = coverage;
                    }

                    for (long i = 0; i < lineCoverageByTestMethod.Value.LineVisitStatus.LongLength; i++)
                    {
                        int lineVisitStatus = Math.Max((int)existingTrackedMethodCoverage.LineVisitStatus[i], (int)lineCoverageByTestMethod.Value.LineVisitStatus[i]);

                        existingTrackedMethodCoverage.LineVisitStatus[i] = (LineVisitStatus)lineVisitStatus;
                    }

                    this.lineCoveragesByTestMethod[lineCoverageByTestMethod.Key] = existingTrackedMethodCoverage;
                }
            }

            if (file.branches != null)
            {
                if (this.branches == null)
                {
                    this.branches = new Dictionary <int, ICollection <Branch> >();
                }

                foreach (var branchByLine in file.branches)
                {
                    ICollection <Branch> existingBranches = null;

                    if (this.branches.TryGetValue(branchByLine.Key, out existingBranches))
                    {
                        foreach (var branch in branchByLine.Value)
                        {
                            Branch existingBranch = existingBranches.FirstOrDefault(b => b.Equals(branch));
                            if (existingBranch != null)
                            {
                                existingBranch.BranchVisits += branch.BranchVisits;
                            }
                            else
                            {
                                existingBranches.Add(branch);
                            }
                        }
                    }
                    else
                    {
                        this.branches.Add(branchByLine);
                    }
                }
            }
        }