public bool Test_IsIn_List_with_comparer(string commaDelimitedArray, string value)
        {
            var enumerable = commaDelimitedArray == null
                ? null
                : commaDelimitedArray.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var caseInsensitiveComparer = EqualityComparerFunc <string> .Create((s1, s2) => string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase));

            return(value.IsIn(enumerable, caseInsensitiveComparer));
        }
        public bool Compare_Contains_Tests(int a, int b, int c, int d, int e, int search)
        {
            Func <int, int, bool> absoluteEqualityFunc = (x, y) =>
            {
                return(Math.Abs(x) == Math.Abs(y));
            };

            var list = new[] { a, b, c, d, e };

            var contains = list.Contains(search, EqualityComparerFunc <int> .Create(absoluteEqualityFunc));

            return(contains);
        }
        public string Test_Append_CaseInsensitiveComparer(string commaDelimitedArray, string value)
        {
            var comparer = EqualityComparerFunc <string> .Create(
                (s1, s2) => string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase)
                );

            var enumerable = commaDelimitedArray == null
                ? null
                : commaDelimitedArray.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var result = enumerable.AppendItem(value, comparer);

            return(string.Join(",", result));
        }
        public void GetHashCode_generates_constant_values(string valueList)
        {
            Func <int, int, bool> absoluteEqualityFunc = (x, y) =>
            {
                return(x == y);
            };

            var comparer = EqualityComparerFunc <int> .Create(absoluteEqualityFunc);

            var list = valueList.Split(",".ToCharArray())
                       .Select(x => Convert.ToInt32(x))
                       .ToList();

            var hashCodes = list
                            .Select(x => comparer.GetHashCode(x));

            hashCodes
            .All(hc => hc.Equals(0)).ShouldBeTrue();
        }
Beispiel #5
0
        /// <summary>
        /// Appends the specified item instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable">The enumerable.</param>
        /// <param name="instance">The instance.</param>
        /// <returns>IEnumerable&lt;T&gt;.</returns>
        public static IEnumerable <T> AppendItem <T>(this IEnumerable <T> enumerable, T instance)
        {
            var falseComparer = EqualityComparerFunc <T> .Create((arg1, arg2) => false);

            return(enumerable.AppendItem(instance, falseComparer));
        }