예제 #1
0
        public void CanGetFilteredValues()
        {
            list.Add("foo", DateTime.Now);
            list.Add("bar", new object());
            list.Add("baz", DateTime.Today);

            IEnumerable <object> filtered = list.FindAllValues(delegate(object value)
            {
                return(value is DateTime);
            });
            int count = 0;

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

            Assert.AreEqual(2, count);
        }
예제 #2
0
        public void ShouldReturnValuesThatMatchPredicate()
        {
            ListDictionary <string, int> dict = new ListDictionary <string, int>();

            dict.Add("a", 1);
            dict.Add("a", 1);
            dict.Add("a", 2);
            dict.Add("b", 3);
            dict.Add("b", 5);
            dict.Add("b", 8);

            int[] evens = { 2, 8 };

            List <int> values = new List <int>(dict.FindAllValues(delegate(int i) { return(i % 2 == 0); }));

            Assert.AreEqual(evens.Length, values.Count);
            for (int i = 0; i < evens.Length; ++i)
            {
                Assert.AreEqual(evens[i], values[i], "Mismatch at index {0}", i);
            }
        }