Пример #1
0
        /// <summary>
        /// Created ArrayListSortedMappedQueue with comparable items
        /// </summary>
        /// <param name="keyExtractor">Extracts key from value</param>
        /// <returns>ArrayListSortedMappedQueue</returns>
        public static SortedMappedQueue <TV> Create <T, TV>(Converter <TV, T> keyExtractor)
            where TV : class, IComparable <TV>
        {
            var comparer = Comparers.OfComparables <TV>();

            return(new ArrayListSortedMappedQueue <T, TV>(keyExtractor, comparer));
        }
Пример #2
0
        /// <summary>
        /// Created ArrayListSortedMappedQueue with comparable items.
        /// </summary>
        /// <returns>ArrayListSortedMappedQueue</returns>
        public static SortedMappedQueue <T> Create <T>()
            where T : class, IComparable <T>
        {
            var comparer = Comparers.OfComparables <T>();

            return(Create(comparer));
        }
        public void ShouldCreateComparerOfComparableObjects()
        {
            // given
            var comparer = Comparers.OfComparables <string>();
            var list     = new List <string> {
                "A", "Z", "D", "B", null, "X"
            };

            // when
            list.Sort(comparer);

            // then
            Check.That(list).ContainsExactly("A", "B", "D", "X", "Z", null);
        }
        public void ShouldExtendCollectionBySortMethodWithComparer()
        {
            // given
            var comparer = Comparers.OfComparables <string>().Reverse();
            ICollection <string> collection = new List <string> {
                "D", "B", "A", "C"
            };

            // when
            collection.Sort(comparer);

            // then
            Check.That(collection).ContainsExactly("D", "C", "B", "A");
        }