Esempio n. 1
0
        public void TestEmptyDictionary()
        {
            ImmutableSortedTreeDictionary <int, int> .Builder dictionary             = ImmutableSortedTreeDictionary.CreateBuilder <int, int>();
            ImmutableSortedTreeDictionary <int, int> .Builder.KeyCollection   keys   = dictionary.Keys;
            ImmutableSortedTreeDictionary <int, int> .Builder.ValueCollection values = dictionary.Values;

            Assert.Empty(dictionary);
            Assert.Empty(keys);
            Assert.Empty(values);

#pragma warning disable xUnit2013 // Do not use equality check to check for collection size.
            Assert.Equal(0, dictionary.Count);
            Assert.Equal(0, keys.Count);
            Assert.Equal(0, values.Count);
#pragma warning restore xUnit2013 // Do not use equality check to check for collection size.

            Assert.False(dictionary.ContainsKey(0));
            Assert.False(dictionary.ContainsValue(0));
            Assert.False(dictionary.TryGetValue(0, out _));
            Assert.Equal(0, dictionary.GetValueOrDefault(0));
            Assert.Equal(1, dictionary.GetValueOrDefault(0, 1));
            Assert.Throws <KeyNotFoundException>(() => dictionary[0]);

#pragma warning disable xUnit2017 // Do not use Contains() to check if a value exists in a collection
            Assert.False(keys.Contains(0));
            Assert.False(values.Contains(0));
#pragma warning restore xUnit2017 // Do not use Contains() to check if a value exists in a collection
        }