コード例 #1
0
        public void EnumerationWorksAfterConflictingKvpInsert()
        {
            var orderedDictionary = DictionaryTesting.CreateOrderedDictionary(0);
            var kvp = KeyValuePair.Create(1, 1);

            orderedDictionary.Add(kvp);
            Assert.Throws <ArgumentException>(() => orderedDictionary.Add(kvp));
            var orderedCount = orderedDictionary.Count(_ => true);

            Assert.AreEqual(1, orderedCount);
        }
コード例 #2
0
 public void IsNonExistentKeyRemoveConstantTime()
 {
     DictionaryTesting.TestComplexityGrowth(
         DictionaryTesting.CreateOrderedDictionary,
         dictionary => dictionary.Remove(0),
         (dictionary, count) =>
     {
         for (var i = 0; i < count; i++)
         {
             dictionary.Remove(0);
         }
     });
 }
コード例 #3
0
        public void IsRemoveConstantTime()
        {
            var rng = new Random();

            DictionaryTesting.TestComplexityGrowth(
                DictionaryTesting.CreateOrderedDictionary,
                dictionary => dictionary.Remove(rng.Next()),
                (dictionary, count) =>
            {
                for (var i = 0; i < count; i++)
                {
                    dictionary.Remove(rng.Next(count));
                }
            });
        }
コード例 #4
0
        public void IsNonExistentKvpRemoveConstantTime()
        {
            var kvp = KeyValuePair.Create(1, 1);

            DictionaryTesting.TestComplexityGrowth(
                DictionaryTesting.CreateOrderedDictionary,
                dictionary => dictionary.Remove(kvp),
                (dictionary, count) =>
            {
                for (var i = 0; i < count; i++)
                {
                    dictionary.Remove(kvp);
                }
            });
        }
コード例 #5
0
        public void IsContainsKvpOptimallyImplemented()
        {
            var       kvp      = KeyValuePair.Create(1, 1);
            const int Capacity = 1000000;
            Action <IDictionary <int, int> > act = d => d.Contains(kvp);
            var orderedDictionaryCount           = DictionaryTesting.TestPerformance(
                () => DictionaryTesting.CreateOrderedDictionary(Capacity),
                act);
            var referenceDictionaryCount = DictionaryTesting.TestPerformance(
                () => DictionaryTesting.CreateReferenceDictionary(Capacity),
                act);

            Assert.AreEqual(
                orderedDictionaryCount,
                referenceDictionaryCount,
                referenceDictionaryCount * 0.08,
                "The time-based test performance for Contains(KeyValuePair<,>) in ordered dictionary deviates from reference one too much.");
        }
コード例 #6
0
        public void IsKvpRemoveConstantTime()
        {
            var rng = new Random();

            DictionaryTesting.TestComplexityGrowth(
                DictionaryTesting.CreateOrderedDictionary,
                dictionary =>
            {
                var j   = rng.Next(dictionary.Count);
                var kvp = KeyValuePair.Create(j, j);
                dictionary.Remove(kvp);
            },
                (dictionary, count) =>
            {
                for (var i = 0; i < count; i++)
                {
                    var j   = rng.Next(count);
                    var kvp = KeyValuePair.Create(j, j);
                    dictionary.Remove(kvp);
                }
            });
        }