예제 #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()
                );
        }