private void Run <T>(AutoStopwatch parent, Func <Random, T> getRandomValue) where T : struct, IComparable <T>
        {
            for (int exp = MIN_EXP; exp <= MAX_EXP; exp += EXP_STEP)
            {
                using (var child = parent.CreateChild(prefix: $"{typeof(T).Name} ", postfix: $" (2^{exp})"))
                {
                    T[] randomData1, randomData2;
                    using (var awCompare = child.CreateChild(stepName: "Create Data"))
                    {
                        randomData1 = new T[1 << exp];
                        randomData2 = new T[1 << exp];
                        var random = new Random();
                        for (int i = 0; i < randomData1.Length; i++)
                        {
                            randomData1[i] = getRandomValue(random);
                            randomData2[i] = getRandomValue(random);
                        }
                    }

                    var v = this.RunGenericVectorized(child, randomData1, randomData2);
                    var c = this.RunGenericConventional(child, randomData1, randomData2);

                    using (var awCompare = child.CreateChild(stepName: "Compare Results"))
                    {
                        ArrayComparer.Compare(v.add, c.add);
                        ArrayComparer.Compare(v.sub, c.sub);
                        ArrayComparer.Compare(v.mul, c.mul);
                        ArrayComparer.Compare(v.div, c.div);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Sorts an array of elements, descending or ascending.
        /// </summary>
        /// <typeparam name="TSource">The source type within the collection.</typeparam>
        /// <param name="source">The source collection array.</param>
        /// <param name="descending">Sort in decending order else ascending.</param>
        /// <returns>The sorted array of elements.</returns>
        /// <exception cref="System.ArgumentNullException">Source object can not be null.</exception>
        public static TSource[] Sort <TSource>(
            this IEnumerable <TSource> source, bool descending)
        {
            // If the source object is null.
            if (source == null)
            {
                throw new System.ArgumentNullException();
            }

            int i = 0;

            // Create a new object collection.
            TSource[] objectArray = new TSource[source.Count()];

            // Get the current source enumerator.
            IEnumerator <TSource> data = source.GetEnumerator();

            // For each type in the collection
            // assign the object array with the type.
            while (data.MoveNext())
            {
                objectArray[i++] = (TSource)data.Current;
            }

            // Get the sorted array.
            return(ArrayComparer.Sort <TSource>(objectArray, descending));
        }
예제 #3
0
        public void GetHashCode_Same_For_Matches()
        {
            // NOTE: Equals_True_For_Identical() verifies that baseline and matching return equal.
            // The spec says GetHashCode() should therefore return the same value.
            ArrayComparer <Suggestion, SuggestionComparer> comparer = new ArrayComparer <Suggestion, SuggestionComparer>();

            Assert.Equal(comparer.GetHashCode(baseline), comparer.GetHashCode(matching));
        }
예제 #4
0
 public ComparerCollection()
 {
     Integer          = new ArrayComparer <int>(false);
     ReverseFloat     = new ArrayComparer <float>(true);
     DrawType         = new ArrayComparer <FillType>(false);
     DrawTarget       = new ArrayComparer <CoordinateSpace>(false);
     TextureCoordMode = new ArrayComparer <TextureCoordinateMode>(false);
     ULong            = new ArrayComparer <ulong>(false);
 }
예제 #5
0
        public void IntegerComparer_NotReversed_ExpectResultLessThanZero()
        {
            var comparer = new ArrayComparer <int>(false);

            comparer.SetItems(new int[] { 0, 1 });

            var result = comparer.Compare(0, 1);

            Assert.True(result < 0);
        }
예제 #6
0
        public void IntegerComparer_ComparingEqualValues_ExpectResultEqualToZero()
        {
            var comparer = new ArrayComparer <int>(false);

            comparer.SetItems(new int[] { 2, 2 });

            var result = comparer.Compare(0, 1);

            Assert.True(result == 0);
        }
예제 #7
0
            public void Visit(DictionaryArray array)
            {
                Assert.IsAssignableFrom <DictionaryArray>(_expectedArray);
                DictionaryArray expectedArray      = (DictionaryArray)_expectedArray;
                var             indicesComparer    = new ArrayComparer(expectedArray.Indices, _strictCompare);
                var             dictionaryComparer = new ArrayComparer(expectedArray.Dictionary, _strictCompare);

                array.Indices.Accept(indicesComparer);
                array.Dictionary.Accept(dictionaryComparer);
            }
예제 #8
0
        public void IntegerComparer_Reversed_ExpectResultGreaterThanZero()
        {
            var comparer = new ArrayComparer <int>(true);

            comparer.SetItems(new int[] { 0, 1 });

            var result = comparer.Compare(0, 1);

            Assert.True(result > 0);
        }
예제 #9
0
     static void Main(string[] args)
     {
         var input = new int[][]
         {
             new [] {14, 24, 44, 36, 37, 45},//- here
             new [] {01, 02, 06, 24, 33, 44},
             new [] {10, 17, 34, 40, 44, 45},//- here
             new [] {12, 13, 28, 31, 37, 47},
             new [] {01, 06, 07, 09, 40, 45},
             new [] {01, 05, 06, 19, 35, 44},
             new [] {13, 19, 20, 26, 31, 47},
             new [] {44, 20, 30, 31, 45, 46},//- here
             new [] {02, 04, 14, 23, 30, 34},
             new [] {27, 30, 41, 42, 44, 49},
             new [] {03, 06, 15, 27, 37, 48},
         };
 
         var matches = new List<int[]>();
         for (int i = 0; i < input.Length; i++)
         {
             for (int j = i + 1; j < input.Length; j++)
             {
                 if (i == j) { continue; }
 
                 var match = input[i].Intersect(input[j]).ToArray();
                 if (match.Length > 1) // N
                 {
                     matches.Add(match);
                 }
             }
         }
 
         var comparer = new ArrayComparer<int>();
         var mostCommon = matches
             .GroupBy(p => p, p => string.Join(", ", p), comparer)
 
             // Sort by frequency
             .OrderByDescending(p => p.Count())
 
             // Sort by the group's length
             .ThenByDescending(p => p.Key.Count())
             .FirstOrDefault();
 
         // Show the result
         if (mostCommon != null)
         {
             Console.WriteLine(
                 "Most common: {{{0}}} ({1})",
                 string.Join(", ", mostCommon.Key), mostCommon.Count());
         }
         else
         {
             Console.WriteLine("Not found.");
         }
     }
예제 #10
0
        public void ShouldSetContent()
        {
            var byteArray = new RingbufferByteArray();
            var source    = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            byte[] target = new byte[512];

            byteArray.Set(source);

            byteArray.GetContent(ref target);
            ArrayComparer.AreEqual(byteArray.ByteBuffer, target);
        }
예제 #11
0
        protected virtual void OnSnapshotUpdated(EventArgs e)
        {
            if (_lastSnapshot == null)
            {
                UpdateTypeCache();
            }
            else
            {
                var result = ArrayComparer.CompareArrays(_snapshot.UsingNamespaces, _lastSnapshot.UsingNamespaces, new SnapshotMemberNameComparer());
                if (!result.ArraysAreEqual)
                {
                    RemoveFromTypeCache(result.ElementsMissing.Cast <NetSnapshotMember>());
                    AddToTypeCache(result.ElementsAdded.Cast <NetSnapshotMember>());
                }
            }

            if (SnapshotUpdated != null)
            {
                SnapshotUpdated(this, e);
            }
        }
예제 #12
0
        /// <summary>
        /// Does an intersection of two arrays exist.
        /// </summary>
        /// <typeparam name="TSource">The source type within the collection.</typeparam>
        /// <param name="source">The source collection array.</param>
        /// <param name="arrayB">The array to compare with.</param>
        /// <param name="isEachArraySorted">Are each of the arrays sorted.</param>
        /// <returns>True if an intersection exists; else false.</returns>
        /// <exception cref="System.ArgumentNullException">Source object can not be null.</exception>
        public static bool IntersectionExists <TSource>(
            this IEnumerable <TSource> source, TSource[] arrayB, bool isEachArraySorted)
        {
            // If the source object is null.
            if (source == null)
            {
                throw new System.ArgumentNullException();
            }

            int i = 0;

            // Create a new object collection.
            TSource[] objectArray = new TSource[source.Count()];

            // Get the current source enumerator.
            IEnumerator <TSource> data = source.GetEnumerator();

            // For each type in the collection
            // assign the object array with the type.
            while (data.MoveNext())
            {
                objectArray[i++] = (TSource)data.Current;
            }

            // Get the intersection of the arrays.
            TSource[] result = ArrayComparer.Intersection <TSource>(objectArray, arrayB, isEachArraySorted);

            if (result != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #13
0
        private bool BinaryEquals(byte[] bytes)
        {
            ArrayComparer <byte> comparer = ArrayComparer <byte> .Comparer;

            return(comparer.Equals(this.binaryData, bytes));
        }
예제 #14
0
        public void Comparer_PassingNullItemList_ThrowsException()
        {
            var comparer = new ArrayComparer <int>(false);

            Assert.Throws <Yak2DException>(() => { comparer.SetItems(null); });
        }
예제 #15
0
        public bool Contains(long item)
        {
            StoreSession storeSession = this.session;
            bool         flag         = false;

            byte[] x;
            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                x = this.session.Mailbox.MapiStore.GlobalIdFromId(item);
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.RuleHistoryError, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("RuleHistory.Contains. item = {0}.", item),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.RuleHistoryError, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("RuleHistory.Contains. item = {0}.", item),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            ArrayComparer <byte> comparer = ArrayComparer <byte> .Comparer;

            foreach (byte[] y in this.gids)
            {
                if (comparer.Equals(x, y))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #16
0
 /// <summary>
 /// Primary constructor.
 /// </summary>
 /// <param name="items">
 /// The array of items.
 /// </param>
 public ArrayKey(T[] items)
 {
     Items    = items;
     Comparer = new ArrayComparer <T>();
 }
예제 #17
0
        public void Equals_True_For_Identical()
        {
            ArrayComparer <Suggestion, SuggestionComparer> comparer = new ArrayComparer <Suggestion, SuggestionComparer>();

            Assert.True(comparer.Equals(baseline, matching));
        }
예제 #18
0
        /// <summary>
        /// Remove duplicated sequences and prefixes from test case set.
        /// </summary>
        private List <String[]> RemoveDuplicatedSequences(List <String[]> testCases)
        {
            //1st step - remove duplicated sequences
            List <String[]> withoutRedundance = testCases.Distinct <String[]>(new ArrayComparer()).ToList();

            //2nd step - remove prefix
            List <String[]> withoutPrefix = new List <String[]>();

            //List<String[]> filteredList = new List<String[]>();

            //filters clockwise
            foreach (String[] seq in withoutRedundance)
            {
                bool isPrefixOf = false;

                foreach (String[] seqq in withoutPrefix)
                {
                    if (ArrayComparer.IsPrefixOf(seqq, seq))
                    {
                        withoutPrefix.Remove(seqq);
                        if (!withoutPrefix.Contains(seq))
                        {
                            withoutPrefix.Add(seq);
                        }
                        isPrefixOf = true;
                        break;
                    }
                    else
                    {
                        if (ArrayComparer.IsPrefixOf(seq, seqq))
                        {
                            withoutPrefix.Remove(seq);
                            if (!withoutPrefix.Contains(seqq))
                            {
                                withoutPrefix.Add(seqq);
                            }
                            isPrefixOf = true;
                            break;
                        }
                    }
                }
                if (!isPrefixOf)
                {
                    withoutPrefix.Add(seq);
                }
            }

            withoutPrefix.Reverse();

            ////filters counterclockwise
            //foreach (String[] seq in withoutPrefix)
            //{
            //    bool isPrefixOf = false;
            //    foreach (String[] seqq in filteredList)
            //    {
            //        if (ArrayComparer.IsPrefixOf(seq, seqq))
            //        {
            //            isPrefixOf = true;
            //            break;
            //        }
            //    }

            //    if (!isPrefixOf)
            //        filteredList.Add(seq);
            //}

            return(withoutPrefix);
        }
예제 #19
0
        private int ComputeHashCode()
        {
            ArrayComparer <byte> comparer = ArrayComparer <byte> .Comparer;

            return(comparer.GetHashCode(this.binaryData));
        }
예제 #20
0
        public void Equals_False_For_Mismatches(Suggestion[] data)
        {
            ArrayComparer <Suggestion, SuggestionComparer> comparer = new ArrayComparer <Suggestion, SuggestionComparer>();

            Assert.False(comparer.Equals(baseline, data));
        }
예제 #21
0
        public void GetHashCode_Different_For_Mismatches(Suggestion[] data)
        {
            ArrayComparer <Suggestion, SuggestionComparer> comparer = new ArrayComparer <Suggestion, SuggestionComparer>();

            Assert.NotEqual(comparer.GetHashCode(baseline), comparer.GetHashCode(data));
        }