Пример #1
0
        public void SingleBucketDictionary_OneBucketTwoItemsTest()
        {
            IList <string> bucket = new string[] { "Bucket1Item1", "Bucket1Item2" };

            SortHelpers.ReadOnlySingleBucketDictionary <string, IList <string> > dict = new SortHelpers.ReadOnlySingleBucketDictionary <string, IList <string> >(new KeyValuePair <string, IList <string> >("Bucket1", bucket));
            Assert.Equal(1, dict.Count);

            Assert.True(dict.Contains(new KeyValuePair <string, IList <string> >("Bucket1", bucket)));
            Assert.False(dict.Contains(new KeyValuePair <string, IList <string> >("Bucket1", null)));
            Assert.False(dict.Contains(new KeyValuePair <string, IList <string> >(string.Empty, bucket)));

            Assert.True(dict.ContainsKey("Bucket1"));
            Assert.False(dict.ContainsKey(string.Empty));

            KeyValuePair <string, IList <string> >[] copyToResult = new KeyValuePair <string, IList <string> > [10];
            dict.CopyTo(copyToResult, 0);
            Assert.Equal("Bucket1", copyToResult[0].Key);
            Assert.Equal(2, copyToResult[0].Value.Count);
            Assert.Equal("Bucket1Item1", copyToResult[0].Value[0]);
            Assert.Equal("Bucket1Item2", copyToResult[0].Value[1]);

            Assert.Equal(1, dict.Count());
            Assert.Equal(1, dict.Count(val => val.Key == "Bucket1"));

            foreach (var item in dict)
            {
                Assert.Equal("Bucket1", item.Key);
                Assert.Equal(2, item.Value.Count);
                Assert.Equal("Bucket1Item1", item.Value[0]);
                Assert.Equal("Bucket1Item2", item.Value[1]);
            }

            Assert.Equal(1, dict.Keys.Count);
            foreach (var key in dict.Keys)
            {
                Assert.Equal("Bucket1", key);
            }

            Assert.Equal(1, dict.Values.Count);
            foreach (var val in dict.Values)
            {
                Assert.Equal(2, val.Count);
                Assert.Equal("Bucket1Item1", val[0]);
                Assert.Equal("Bucket1Item2", val[1]);
            }

            Assert.Equal(2, dict["Bucket1"].Count);
            Assert.True(dict.TryGetValue("Bucket1", out bucket) && bucket.Count == 2);
            Assert.False(dict.TryGetValue(string.Empty, out bucket) || bucket != null);
            Assert.False(dict.TryGetValue(null, out bucket) || bucket != null);
            Assert.Throws <System.NotSupportedException>(() => dict[string.Empty] = new string[0]);
        }
Пример #2
0
        public void SingleBucketDictionary_OneBucketEmptyTest()
        {
            IList<string> bucket = new string[0];
            SortHelpers.ReadOnlySingleBucketDictionary<string, IList<string>> dict = new SortHelpers.ReadOnlySingleBucketDictionary<string, IList<string>>(new KeyValuePair<string, IList<string>>("Bucket1", bucket));
            Assert.Equal(1, dict.Count);

            Assert.True(dict.Contains(new KeyValuePair<string, IList<string>>("Bucket1", bucket)));
            Assert.False(dict.Contains(new KeyValuePair<string, IList<string>>("Bucket1", null)));
            Assert.False(dict.Contains(new KeyValuePair<string, IList<string>>(string.Empty, bucket)));

            Assert.True(dict.ContainsKey("Bucket1"));
            Assert.False(dict.ContainsKey(string.Empty));

            KeyValuePair<string, IList<string>>[] copyToResult = new KeyValuePair<string, IList<string>>[10];
            dict.CopyTo(copyToResult, 0);
            Assert.Equal("Bucket1", copyToResult[0].Key);
            Assert.Equal(0, copyToResult[0].Value.Count);

            Assert.Equal(1, dict.Count());
            Assert.Equal(1, dict.Count(val => val.Key == "Bucket1"));

            foreach (var item in dict)
            {
                Assert.Equal("Bucket1", item.Key);
                Assert.Equal(0, item.Value.Count);
            }

            Assert.Equal(1, dict.Keys.Count);
            foreach (var key in dict.Keys)
            {
                Assert.Equal("Bucket1", key);
            }

            Assert.Equal(1, dict.Values.Count);
            foreach (var val in dict.Values)
            {
                Assert.Equal(0, val.Count);
            }

            Assert.Equal(0, dict["Bucket1"].Count);

            Assert.True(dict.TryGetValue("Bucket1", out bucket) && bucket.Count == 0);
            Assert.False(dict.TryGetValue(string.Empty, out bucket) || bucket != null);
            Assert.False(dict.TryGetValue(null, out bucket) || bucket != null);
            Assert.Throws<NotSupportedException>(() => dict[string.Empty] = new string[0]);
        }
Пример #3
0
        public void SingleBucketDictionary_TwoBucketEmptyTest()
        {
            IList <string> bucket1 = new string[0];
            IList <string> bucket2 = new string[0];
            Dictionary <string, IList <string> > buckets = new Dictionary <string, IList <string> >();

            buckets["Bucket1"] = bucket1;
            buckets["Bucket2"] = bucket2;

            SortHelpers.ReadOnlySingleBucketDictionary <string, IList <string> > dict = new SortHelpers.ReadOnlySingleBucketDictionary <string, IList <string> >(buckets);
            Assert.Equal(2, dict.Count);

            Assert.True(dict.Contains(new KeyValuePair <string, IList <string> >("Bucket1", bucket1)));
            Assert.False(dict.Contains(new KeyValuePair <string, IList <string> >("Bucket1", null)));
            Assert.False(dict.Contains(new KeyValuePair <string, IList <string> >(string.Empty, bucket1)));

            Assert.True(dict.Contains(new KeyValuePair <string, IList <string> >("Bucket2", bucket2)));
            Assert.False(dict.Contains(new KeyValuePair <string, IList <string> >("Bucket2", null)));
            Assert.False(dict.Contains(new KeyValuePair <string, IList <string> >(string.Empty, bucket2)));

            Assert.True(dict.ContainsKey("Bucket1"));
            Assert.True(dict.ContainsKey("Bucket2"));
            Assert.False(dict.ContainsKey(string.Empty));

            KeyValuePair <string, IList <string> >[] copyToResult = new KeyValuePair <string, IList <string> > [10];
            dict.CopyTo(copyToResult, 0);
            Assert.Equal("Bucket1", copyToResult[0].Key);
            Assert.Equal("Bucket2", copyToResult[1].Key);
            Assert.Equal(0, copyToResult[0].Value.Count);
            Assert.Equal(0, copyToResult[1].Value.Count);

            Assert.Equal(2, dict.Count());
            Assert.Equal(1, dict.Count(val => val.Key == "Bucket1"));
            Assert.Equal(1, dict.Count(val => val.Key == "Bucket2"));

            foreach (var item in dict)
            {
                Assert.True(item.Key == "Bucket1" || item.Key == "Bucket2");
                Assert.Equal(0, item.Value.Count);
            }

            Assert.Equal(2, dict.Keys.Count);
            foreach (var key in dict.Keys)
            {
                Assert.True(key == "Bucket1" || key == "Bucket2");
            }

            Assert.Equal(2, dict.Values.Count);
            foreach (var val in dict.Values)
            {
                Assert.Equal(0, val.Count);
            }

            Assert.Equal(0, dict["Bucket1"].Count);
            Assert.Equal(0, dict["Bucket2"].Count);
            Assert.True(dict.TryGetValue("Bucket1", out bucket1) && bucket1.Count == 0);
            Assert.True(dict.TryGetValue("Bucket2", out bucket2) && bucket2.Count == 0);
            Assert.Throws <System.NotSupportedException>(() => dict[string.Empty] = new string[0]);
        }
Пример #4
0
        public void SingleBucketDictionary_TwoBuckettOneItemTest()
        {
            IList<string> bucket1 = new string[] { "Bucket1Item1" };
            IList<string> bucket2 = new string[] { "Bucket1Item1" };
            Dictionary<string, IList<string>> buckets = new Dictionary<string, IList<string>>();
            buckets["Bucket1"] = bucket1;
            buckets["Bucket2"] = bucket2;

            SortHelpers.ReadOnlySingleBucketDictionary<string, IList<string>> dict = new SortHelpers.ReadOnlySingleBucketDictionary<string, IList<string>>(buckets);
            Assert.Equal(2, dict.Count);

            Assert.True(dict.Contains(new KeyValuePair<string, IList<string>>("Bucket1", bucket1)));
            Assert.False(dict.Contains(new KeyValuePair<string, IList<string>>("Bucket1", null)));
            Assert.False(dict.Contains(new KeyValuePair<string, IList<string>>(string.Empty, bucket1)));

            Assert.True(dict.Contains(new KeyValuePair<string, IList<string>>("Bucket2", bucket2)));
            Assert.False(dict.Contains(new KeyValuePair<string, IList<string>>("Bucket2", null)));
            Assert.False(dict.Contains(new KeyValuePair<string, IList<string>>(string.Empty, bucket2)));

            Assert.True(dict.ContainsKey("Bucket1"));
            Assert.True(dict.ContainsKey("Bucket2"));
            Assert.False(dict.ContainsKey(string.Empty));

            KeyValuePair<string, IList<string>>[] copyToResult = new KeyValuePair<string, IList<string>>[10];
            dict.CopyTo(copyToResult, 0);
            Assert.Equal("Bucket1", copyToResult[0].Key);
            Assert.Equal("Bucket2", copyToResult[1].Key);
            Assert.Equal(1, copyToResult[0].Value.Count);
            Assert.Equal(1, copyToResult[1].Value.Count);

            Assert.Equal(2, dict.Count());
            Assert.Equal(1, dict.Count(val => val.Key == "Bucket1"));
            Assert.Equal(1, dict.Count(val => val.Key == "Bucket2"));

            foreach (var item in dict)
            {
                Assert.True(item.Key == "Bucket1" || item.Key == "Bucket2");
                Assert.Equal(1, item.Value.Count);
                Assert.Equal("Bucket1Item1", item.Value[0]);
            }

            Assert.Equal(2, dict.Keys.Count);
            foreach (var key in dict.Keys)
            {
                Assert.True(key == "Bucket1" || key == "Bucket2");
            }

            Assert.Equal(2, dict.Values.Count);
            foreach (var val in dict.Values)
            {
                Assert.Equal(1, val.Count);
                Assert.Equal("Bucket1Item1", val[0]);
            }

            Assert.Equal(1, dict["Bucket1"].Count);
            Assert.Equal(1, dict["Bucket2"].Count);
            Assert.True(dict.TryGetValue("Bucket1", out bucket1) && bucket1.Count == 1);
            Assert.True(dict.TryGetValue("Bucket2", out bucket2) && bucket2.Count == 1);
            Assert.Throws<System.NotSupportedException>(() => dict[string.Empty] = new string[0]);
        }