public void TrimExcess_Generic_ClearThenTrimNonEmptyDictionary_SetsCapacityTo3(int count)
        {
            LinkedDictionary <TKey, TValue> dictionary = (LinkedDictionary <TKey, TValue>)GenericIDictionaryFactory(count);

            Assert.Equal(count, dictionary.Count);
            // The smallest possible capacity size after clearing a dictionary is 3
            dictionary.Clear();
            dictionary.TrimExcess();
            Assert.Equal(3, dictionary.EnsureCapacity(0));
        }
        public void Clear_OnEmptyCollection_DoesNotInvalidateEnumerator()
        {
            if (ModifyEnumeratorAllowed.HasFlag(ModifyOperation.Clear))
            {
                IDictionary dictionary = new LinkedDictionary <string, string>();
                IEnumerator valuesEnum = dictionary.GetEnumerator();

                dictionary.Clear();
                Assert.Empty(dictionary);
                Assert.False(valuesEnum.MoveNext());
            }
        }
Exemple #3
0
        public void SetMetadata(IDictionary <ProjectMetadataKey, string> metadata)
        {
            PreConditions.Argument("metadata").Value(metadata).IsNotNull();

            foreach (KeyValuePair <ProjectMetadataKey, string> item in metadata)
            {
                if (!Enum.IsDefined(typeof(ProjectMetadataKey), item.Key))
                {
                    throw new InvalidEnumArgumentException("Invalid metadata key.");
                }
                if (item.Key == ProjectMetadataKey.FileVersion && item.Value != FileVersion)
                {
                    throw new ArgumentException("Incorrect file version.", "metadata");
                }
                if (item.Value == null)
                {
                    throw new ArgumentException("Null value.", "metadata");
                }
            }

            if (_metadata.IsEqual(metadata))
            {
                return;
            }

            // Copy metadata
            _metadata.Clear();
            _metadata.Add(ProjectMetadataKey.FileVersion, FileVersion);

            foreach (KeyValuePair <ProjectMetadataKey, string> item in metadata)
            {
                if (item.Key != ProjectMetadataKey.FileVersion)
                {
                    _metadata.Add(item.Key, item.Value);
                }
            }

            UpdateProject(ProjectChangedType.MetadataChanged);
        }
 public void RemoveAll()
 {
     m_CoroutineMap.Clear();
 }
Exemple #5
0
 protected void Reset()
 {
     m_LoadedCallbackList.Clear();
     m_ProgressCallbackList.Clear();
 }
Exemple #6
0
        public static void LinkedDictionaryTest()
        {
            LinkedDictionary <string, int> ldEmpty = new LinkedDictionary <string, int>();
            LinkedDictionary <string, int> a       = new LinkedDictionary <string, int>();

            a.Add("a1", 1);
            a.Add("a12", 12);
            a.Add("a123", 123);
            a.Add("a4", 4);
            a.Add("a5", 5);

            #region Pseudo-LINQ-Extensions
            Assert.AreEqual("a1", a.First().Key);
            Assert.AreEqual(1, a.First().Value);
            Assert.AreEqual("a5", a.Last().Key);
            Assert.AreEqual(5, a.Last().Value);
            Assert.Throws <InvalidOperationException>(() => ldEmpty.First());
            Assert.Throws <InvalidOperationException>(() => ldEmpty.Last());
            Assert.DoesNotThrow(() => ldEmpty.FirstOrDefault());
            Assert.DoesNotThrow(() => ldEmpty.LastOrDefault());
            Assert.AreEqual(default(KeyValuePair <string, int>), ldEmpty.FirstOrDefault());
            Assert.AreEqual(default(KeyValuePair <string, int>), ldEmpty.LastOrDefault());

            Assert.DoesNotThrow(() => ldEmpty.Reverse());
            List <KeyValuePair <string, int> > reversed = new List <KeyValuePair <string, int> >(a.Reverse());
            Assert.AreEqual(a.Count, reversed.Count);
            Assert.AreEqual("a5", reversed[0].Key);
            Assert.AreEqual(5, reversed[0].Value);
            Assert.AreEqual("a4", reversed[1].Key);
            Assert.AreEqual(4, reversed[1].Value);
            Assert.AreEqual("a123", reversed[2].Key);
            Assert.AreEqual(123, reversed[2].Value);
            Assert.AreEqual("a12", reversed[3].Key);
            Assert.AreEqual(12, reversed[3].Value);
            Assert.AreEqual("a1", reversed[4].Key);
            Assert.AreEqual(1, reversed[4].Value);
            #endregion

            Assert.AreEqual(5, a.Count);

            Assert.IsTrue(a.ContainsKey("a4"));
            Assert.IsTrue(a.ContainsKey("a123"));

            Assert.IsTrue(a.Remove("a123"));
            Assert.IsFalse(a.Remove("a123"));
            Assert.IsFalse(a.ContainsKey("a123"));

            Assert.AreEqual(4, a.Count);

            List <string> keys   = new List <string>(a.Keys);
            List <int>    values = new List <int>(a.Values);
            List <KeyValuePair <string, int> > kv = new List <KeyValuePair <string, int> >(a);

            Assert.AreEqual("a1", keys[0]);
            Assert.AreEqual("a12", keys[1]);
            Assert.AreEqual("a4", keys[2]);
            Assert.AreEqual("a5", keys[3]);

            Assert.AreEqual(1, values[0]);
            Assert.AreEqual(12, values[1]);
            Assert.AreEqual(4, values[2]);
            Assert.AreEqual(5, values[3]);

            Assert.AreEqual("a1", kv[0].Key);
            Assert.AreEqual("a12", kv[1].Key);
            Assert.AreEqual("a4", kv[2].Key);
            Assert.AreEqual("a5", kv[3].Key);

            Assert.AreEqual(1, kv[0].Value);
            Assert.AreEqual(12, kv[1].Value);
            Assert.AreEqual(4, kv[2].Value);
            Assert.AreEqual(5, kv[3].Value);

            a.Clear();
            Assert.AreEqual(0, a.Count);
        }