< Summary

Information
Class: Ice.Internal.DictionaryExtensions
Assembly: Ice
File(s): /home/runner/work/ice/ice/csharp/src/Ice/Internal/DictionaryExtensions.cs
Tag: 71_18251537082
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage
100%
Covered methods: 1
Total methods: 1
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DictionaryEqual<TKey, TValue>(...)100%1010100%

File(s)

/home/runner/work/ice/ice/csharp/src/Ice/Internal/DictionaryExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3#nullable enable
 4
 5namespace Ice.Internal;
 6
 7/// <summary>Extension methods for dictionaries.</summary>
 8public static class DictionaryExtensions
 9{
 10    /// <summary>Checks if two dictionaries are equal. The order of the elements in the dictionaries does not
 11    /// matter.</summary>
 12    /// <typeparam name="TKey">The type of the keys in the dictionaries.</typeparam>
 13    /// <typeparam name="TValue">The type of the values in the dictionaries.</typeparam>
 14    /// <param name="lhs">The first dictionary to compare.</param>
 15    /// <param name="rhs">The second dictionary to compare.</param>
 16    /// <param name="valueComparer">The comparer to use to compare the values in the dictionaries or null to use the
 17    /// value's default equality comparer.</param>
 18    /// <returns>True if the dictionaries are equal; false, otherwise.</returns>
 19    public static bool DictionaryEqual<TKey, TValue>(
 20        this IReadOnlyDictionary<TKey, TValue> lhs,
 21        IReadOnlyDictionary<TKey, TValue> rhs,
 22        IEqualityComparer<TValue>? valueComparer = null)
 23    {
 124        if (rhs.Count != lhs.Count)
 25        {
 126            return false;
 27        }
 28
 129        valueComparer ??= EqualityComparer<TValue>.Default;
 30
 131        foreach ((TKey key, TValue value) in lhs)
 32        {
 133            if (!rhs.TryGetValue(key, out TValue? otherValue) || !valueComparer.Equals(value, otherValue))
 34            {
 135                return false;
 36            }
 37        }
 38
 139        return true;
 140    }
 41}