コード例 #1
0
        public void EqualsTest()
        {
            var comparer = new IntEqualityComparer(5);
            var res      = comparer.Equals(1, 2);

            Assert.AreEqual(true, res);
        }
コード例 #2
0
        public void Test_WithoutElement_Int_WithCompare()
        {
            var compare  = new IntEqualityComparer();
            var sequence = new[] { 11, 22, 33 };
            var result   = sequence.WithoutElement(44, compare);

            result.Should().BeEquivalentTo(new[] { 11, 22, 33 });
        }
コード例 #3
0
        public void CheckIfDistinctWorksCorrectly()
        {
            int[] source = { 11, 12, 53, 12, 15, 15, 36, 87, 78, 90, 11 };
            int[] result = { 11, 12, 53, 15, 36, 87, 78, 90 };
            IntEqualityComparer equal = new IntEqualityComparer();

            Assert.Equal(result, DataStructures.LinqFunctions.Distinct <int>(source, equal));
        }
コード例 #4
0
        public void CheckIfExceptArgumentWorksCorrectly()
        {
            int[] first  = null;
            int[] second = { 3, 6, 9, 12, 12, 15 };
            int[] final  = { 2, 4, 8, 10 };
            IntEqualityComparer equal = new IntEqualityComparer();

            Assert.Throws <ArgumentNullException>(() => final.Equals(DataStructures.LinqFunctions.Except <int>(first, second, equal)));
        }
コード例 #5
0
        public void CheckIfExceptWorksCorrectly()
        {
            int[] first  = { 2, 4, 6, 8, 10, 12 };
            int[] second = { 3, 6, 9, 12, 12, 15 };
            int[] final  = { 2, 4, 8, 10 };
            IntEqualityComparer equal = new IntEqualityComparer();

            Assert.Equal(final, DataStructures.LinqFunctions.Except <int>(first, second, equal));
        }
コード例 #6
0
        public void IntEqualityComparerTest()
        {
            var source = new List<int> { 1, 5, 5, 2,7,12,15,18,20,24,25,10,5,1,8,11,30 };

            var comparer = new IntEqualityComparer(5);

            source.Sort();
            var res = source.GroupBy(g => g, comparer);

            Assert.AreEqual(5, res.Count());
        }
コード例 #7
0
        public void CheckIfDistinctArgumentWorksCorrectly()
        {
            int[] source = null;
            int[] result = { 53, 12, 15, 36, 87, 78, 90, 11 };
            IntEqualityComparer equal = new IntEqualityComparer();

            Func <int, bool> isString = x => Equals(x, x.ToString());

            Assert.Throws <ArgumentNullException>(() =>
                                                  DataStructures.LinqFunctions.All <int>(DataStructures.LinqFunctions.Distinct <int>(source, equal), isString));
        }
コード例 #8
0
        public void IntEqualityComparerTest()
        {
            var source = new List <int> {
                1, 5, 5, 2, 7, 12, 15, 18, 20, 24, 25, 10, 5, 1, 8, 11, 30
            };

            var comparer = new IntEqualityComparer(5);

            source.Sort();
            var res = source.GroupBy(g => g, comparer);

            Assert.AreEqual(5, res.Count());
        }
コード例 #9
0
ファイル: ObjectGraph.cs プロジェクト: nomada2/utilities
 internal ObjectGraph(ReadNewLog readNewLog, int tickIndex)
 {
     //
     // TODO: Add constructor logic here
     //
     idToObject                 = new IdToObject();
     typeNameToGcType           = new Dictionary <string, GcType>();
     intEqualityComparer        = new IntEqualityComparer();
     typeIdToGcType             = new Dictionary <int, GcType>(intEqualityComparer);
     addressToForwardReferences = new Dictionary <ulong, ForwardReference>();
     unknownTypeId              = GetOrCreateGcType("<unknown type>");
     this.readNewLog            = readNewLog;
     this.tickIndex             = tickIndex;
     empty = true;
 }
コード例 #10
0
        public static void ExampleCollactionTypes()
        {
            //interfaces

            IEnumerable <int> iEnumerable;                 //:System.Collections.IEnumerable
            IEnumerator <int> iEnumerator;                 //:System.Collections.iEnumerator
            ICollection <int> iCollection;                 //:System.Collections.IEnumerable<>
            IComparer <int>   iComparer;                   // It provides a way to customize the sort order of a collection. (Used: List<T>.Sort
                                                           //                                                                       List<T>.BinarySearch,
                                                           //                                                                       SortedDictionary<TKey,TValue> ,
                                                           //                                                                       SortedList<TKey,TValue>  )
            IEqualityComparer <int> iEqualityComparer;     //Defines methods to support the comparison of objects for equality.

            IDictionary <int, int> iDictionary;            //ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>,
                                                           //IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>
                                                           // replaces hashtable with DictionaryEntry(KeyValuePair)

            IList <int> iList;                             //Represents a collection of objects that can be individually accessed by index.
                                                           //  Generic.ICollection<T>,
                                                           //  Generic.IEnumerable<T>
            ISet <int> iSet;                               //  Generic.ICollection<T>,
                                                           //  Generic.IEnumerable<T>

            IReadOnlyCollection <int> iReadOnlyCollection; // System.Collections.Generic.IEnumerable<out T>
            IReadOnlyDictionary <int, int>
            iReadOnlyDictionary;                           // System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>,
            // System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>
            IReadOnlyList <int> iReadOnlyList;             //System.Collections.Generic.IEnumerable<out T>,
            //System.Collections.Generic.IReadOnlyCollection<out T>


            //
            ISerializable            iSerializable;
            IDeserializationCallback iSerializableCallback;
            //Classes

            Comparer <int> comparer = new CollectionGenericFramework.IntComparer();  //Abstract

            iComparer = comparer;
            IComparer iComparerNonGeneric = comparer;

            Dictionary <int, int> .KeyCollection dicKeyCollection =
                new Dictionary <int, int> .KeyCollection(new Dictionary <int, int>() { { 4, 5 } });

            iCollection         = dicKeyCollection;
            iEnumerable         = dicKeyCollection;
            iCollection         = dicKeyCollection;
            iReadOnlyCollection = dicKeyCollection;

            Dictionary <int, int> .ValueCollection valueCollection =
                new Dictionary <int, int> .ValueCollection(new Dictionary <int, int>() { { 4, 5 } });

            iCollection         = valueCollection;
            iEnumerable         = valueCollection;
            iCollection         = valueCollection;
            iReadOnlyCollection = valueCollection;

            Dictionary <int, int> dictionary01 = new Dictionary <int, int>()
            {
                { 4, 5 }
            };

            iDictionary = dictionary01;
            IEnumerable <KeyValuePair <int, int> > enumarableForDict       = dictionary01;
            ICollection <KeyValuePair <int, int> > collectionKeyValuePairs = dictionary01;
            ICollection iCollectionNonGen = dictionary01;

            iReadOnlyDictionary = dictionary01;
            IReadOnlyCollection <KeyValuePair <int, int> > iReadOnlyCollectionDict = dictionary01;

            iSerializable         = dictionary01;
            iSerializableCallback = dictionary01;

            EqualityComparer <int> equalityComparer = new IntEqualityComparer(); //Abstract

            iEqualityComparer = equalityComparer;

            HashSet <int> hashSet = new HashSet <int>()
            {
                1, 2, 3
            };

            iCollection         = hashSet;
            iEnumerable         = hashSet;
            iCollection         = hashSet;
            iReadOnlyCollection = hashSet;
            iSet = hashSet;

            iSerializable         = hashSet;
            iSerializableCallback = hashSet;

            LinkedList <int> ll = new LinkedList <int>(); //System.Collections.Generic.ICollection<T>,
                                                          //System.Collections.Generic.IEnumerable<T>,
                                                          //System.Collections.Generic.IReadOnlyCollection<T>,
                                                          //System.Collections.ICollection,
                                                          //System.Runtime.Serialization.IDeserializationCallback,
                                                          //System.Runtime.Serialization.ISerializable
            //Each node in linke list is LinkedListNode<T>
            LinkedListNode <int> listNode = new LinkedListNode <int>(1);

            //The only multithreaded scenario supported by LinkedList<T> is multithreaded read operations.
            string[]            words    = { "the", "fox", "jumps", "over", "the", "dog" };
            LinkedList <string> sentence = new LinkedList <string>(words);

            sentence.AddFirst("today");
            sentence.AddLast("mark1");
            sentence.RemoveFirst();
            sentence.RemoveLast();

            List <int> list = new List <int>();    //System.Collections.Generic.ICollection<T>,
                                                   //System.Collections.Generic.IEnumerable<T>,
                                                   //System.Collections.Generic.IList<T>,
                                                   //System.Collections.Generic.IReadOnlyCollection<T>,
                                                   //System.Collections.Generic.IReadOnlyList<T>,
                                                   //System.Collections.IList

            Queue <int> queue = new Queue <int>(); //System.Collections.Generic.IEnumerable<T>,

            //System.Collections.Generic.IReadOnlyCollection<T>,
            //System.Collections.ICollection
            queue.Enqueue(1);
            queue.Dequeue();
            SortedDictionary <int, int> .KeyCollection keyCollection;
            //System.Collections.Generic.ICollection<TKey>,
            //System.Collections.Generic.IEnumerable<TKey>,
            //System.Collections.Generic.IReadOnlyCollection<TKey>,
            //System.Collections.ICollection

            SortedDictionary <int, int> .ValueCollection valueCollection1;
            //System.Collections.Generic.ICollection<TValue>,
            //System.Collections.Generic.IEnumerable<TValue>,
            //System.Collections.Generic.IReadOnlyCollection<TValue>,
            //System.Collections.ICollection
            SortedList <int, int> sortedList;
            //System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>,
            //System.Collections.Generic.IDictionary<TKey,TValue>,
            //System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>,
            //System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>,
            //System.Collections.Generic.IReadOnlyDictionary<TKey,TValue>, System.Collections.IDictionary
            SortedSet <int> sortedSet;
            //System.Collections.Generic.ICollection<T>,
            //System.Collections.Generic.IEnumerable<T>,
            //System.Collections.Generic.IReadOnlyCollection<T>,
            //System.Collections.Generic.ISet<T>,
            //System.Collections.ICollection,
            //System.Runtime.Serialization.IDeserializationCallback,
            //System.Runtime.Serialization.ISerializable

            Stack <int> stack;                   //(LIFO)
                                                 //System.Collections.Generic.IEnumerable<T>,
                                                 //System.Collections.Generic.IReadOnlyCollection<T>,
                                                 //System.Collections.ICollection

            SynchronizedCollection <int> synchronizedCollection;
            // stores data in a List<T> container and it is thread-safe
            //System.Collections.Generic.ICollection<T>,
            //System.Collections.Generic.IEnumerable<T>
            //System.Collections.Generic.IList<T>,
            //System.Collections.IList
            SynchronizedKeyedCollection <int, int> synchronizedKeyedCollection;  //Provides a thread-safe collection, grouped by keys.
            //System.Collections.Generic.SynchronizedCollection<T>

            SynchronizedReadOnlyCollection <int> synchronizedReadOnlyCollection;  //	Provides a thread-safe, read-onl
            //System.Collections.Generic.ICollection<T>,
            //System.Collections.Generic.IEnumerable<T>,
            //System.Collections.Generic.IList<T>,
            //System.Collections.IList
        }
コード例 #11
0
 public void EqualsTest()
 {
     var comparer = new IntEqualityComparer(5);
     var res = comparer.Equals(1, 2);
     Assert.AreEqual(true, res);
 }