< Summary

Class:NanoCLang.Entities.HeapElementComparer
Assembly:NanoCLang
File(s):C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\HeapElementComparer.cs
Covered lines:10
Uncovered lines:1
Coverable lines:11
Total lines:31
Line coverage:90.9% (10 of 11)
Covered branches:5
Total branches:6
Branch coverage:83.3% (5 of 6)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Default()100%1100%
CastWhere(...)100%4100%
GetDirectBindings(...)100%1100%
GetOthers(...)100%1100%
Equals(...)50%2100%
GetHashCode(...)100%10%

File(s)

C:\GitLab-Runner\builds\JxAESPd8\0\chenmichael\nanoc\src\NanoCLang\HeapElementComparer.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3
 4namespace NanoCLang.Entities {
 5    /// <summary>
 6    /// Provides a class that compares two arrays of heap elements by building a heap from them.
 7    /// </summary>
 8    public class HeapElementComparer : IEqualityComparer<IHeapElement[]> {
 9        /// <summary>
 10        /// Returns a default equality comparer for heap elements.
 11        /// </summary>
 4512        public static HeapElementComparer Default { get; } = new HeapElementComparer();
 66813        private static IEnumerable<T> CastWhere<T>(IEnumerable<IHeapElement> items) where T : class => items.Where(i => 
 9114        private static Heap GetDirectBindings(IHeapElement[] x) => new Heap(CastWhere<LocationBinding>(x).Concat(CastWhe
 11615        private static IEnumerable<IHeapElement> GetOthers(IHeapElement[] x) => CastWhere<FunctionCallExpression>(x).Ord
 16        /// <summary>
 17        /// Compares the heap element lists by creating a heap from the locations and comparing that, after that compari
 18        /// </summary>
 19        /// <param name="x">Left operand</param>
 20        /// <param name="y">Right operand</param>
 21        /// <returns>True if the heap elements refer to the same heap after construction with the global environment.</r
 4422        public bool Equals(IHeapElement[] x, IHeapElement[] y) {
 4423            var l = GetDirectBindings(x);
 4424            var r = GetDirectBindings(y);
 4425            if (!EqualityComparer<Heap>.Default.Equals(l, r)) return false;
 4426            return GetOthers(x).SequenceEqual(GetOthers(y));
 4427        }
 28        /// <inheritdoc cref="IEqualityComparer{T}.GetHashCode(T)"/>
 029        public int GetHashCode(IHeapElement[] obj) => throw new System.NotImplementedException();
 30    }
 31}