Beispiel #1
0
        public void ToImmutableDictionary()
        {
            ImmutableSegmentedDictionary <int, int> .Builder builder =
                ImmutableSegmentedDictionary.CreateBuilder <int, int>();
            builder.Add(0, 0);
            builder.Add(1, 1);
            builder.Add(2, 2);

            var dictionary = builder.ToImmutableSegmentedDictionary();

            Assert.Equal(0, dictionary[0]);
            Assert.Equal(1, dictionary[1]);
            Assert.Equal(2, dictionary[2]);

            builder[1] = 5;
            Assert.Equal(5, builder[1]);
            Assert.Equal(1, dictionary[1]);

            builder.Clear();
            Assert.True(builder.ToImmutableSegmentedDictionary().IsEmpty);
            Assert.False(dictionary.IsEmpty);

            ImmutableSegmentedDictionary <int, int> .Builder?nullBuilder = null;
            Assert.Throws <ArgumentNullException>(
                "builder",
                () => nullBuilder !.ToImmutableSegmentedDictionary()
                );
        }
        public void Clear_HasComparer_ReturnsEmptyWithOriginalComparer()
        {
            ImmutableSegmentedDictionary <string, int> dictionary = new Dictionary <string, int>
            {
                { "a", 1 }
            }.ToImmutableSegmentedDictionary(StringComparer.OrdinalIgnoreCase);

            ImmutableSegmentedDictionary <string, int> clearedDictionary = dictionary.Clear();

            Assert.False(IsSame(ImmutableSegmentedDictionary <string, int> .Empty, clearedDictionary.Clear()));
            Assert.NotEmpty(dictionary);

            clearedDictionary = clearedDictionary.Add("a", 1);
            Assert.True(clearedDictionary.ContainsKey("A"));
        }