예제 #1
0
        public void TestTryGetKey()
        {
            ImmutableSortedTreeDictionary <int, int> .Builder dictionary = ImmutableSortedTreeDictionary.CreateBuilder <int, int>();
            Assert.False(dictionary.TryGetKey(0, out var key));
            Assert.Equal(0, key);

            dictionary.Add(1, 2);
            Assert.True(dictionary.TryGetKey(1, out key));
            Assert.Equal(1, key);
        }
예제 #2
0
        public void TestGetValueOrDefault()
        {
            ImmutableSortedTreeDictionary <int, int> .Builder dictionary = ImmutableSortedTreeDictionary.CreateBuilder <int, int>();
            Assert.Equal(0, dictionary.GetValueOrDefault(1));
            Assert.Equal(0, dictionary.GetValueOrDefault(1, 0));
            Assert.Equal(1, dictionary.GetValueOrDefault(1, 1));

            dictionary.Add(1, 2);
            Assert.Equal(2, dictionary.GetValueOrDefault(1));
            Assert.Equal(2, dictionary.GetValueOrDefault(1, 0));
            Assert.Equal(2, dictionary.GetValueOrDefault(1, 1));
        }
예제 #3
0
        public void TestRemoveRange()
        {
            ImmutableSortedTreeDictionary <int, int> .Builder dictionary = ImmutableSortedTreeDictionary.CreateBuilder <int, int>();
            for (int i = 0; i < 10; i++)
            {
                dictionary.Add(i, i);
            }

            int[] itemsToRemove = dictionary.Keys.Where(i => (i & 1) == 0).ToArray();
            dictionary.RemoveRange(itemsToRemove);
            Assert.Equal(new[] { 1, 3, 5, 7, 9 }.Select(x => new KeyValuePair <int, int>(x, x)), dictionary);

            Assert.Throws <ArgumentNullException>("keys", () => dictionary.RemoveRange(null !));
        }