Пример #1
0
        public void ShouldReturnValuesWhereKeyMatchesPredicate()
        {
            ListDictionary <string, int> dict = new ListDictionary <string, int>();

            dict.Add("a", 1);
            dict.Add("a", 1);
            dict.Add("a", 2);
            dict.Add("bar", 3);
            dict.Add("bar", 5);
            dict.Add("bar", 8);
            dict.Add("c", 13);
            dict.Add("c", 21);
            dict.Add("dar", 34);

            // We can't assume that the keys come out in sorted order,
            // so we'll keep a set of the expected numbers instead, and
            // pick them out.

            Dictionary <int, int> expected = new Dictionary <int, int>();

            expected[3]  = 0;
            expected[5]  = 0;
            expected[8]  = 0;
            expected[34] = 0;

            foreach (int value in dict.FindAllValuesByKey(
                         delegate(string key) { return(key.Length == 3); }))
            {
                Assert.IsTrue(expected.ContainsKey(value));
                expected.Remove(value);
            }
            Assert.AreEqual(0, expected.Count);
        }
Пример #2
0
        public void CanGetFilteredValuesByKeys()
        {
            list.Add("foo", new object());
            list.Add("bar", new object());
            list.Add("baz", new object());

            IEnumerable <object> filtered = list.FindAllValuesByKey(delegate(string key)
            {
                return(key.StartsWith("b"));
            });

            int count = 0;

            foreach (object obj in filtered)
            {
                count++;
            }

            Assert.AreEqual(2, count);
        }