예제 #1
0
파일: RWList.cs 프로젝트: lydonchandra/Loyc
        public void TestSelect()
        {
            RWList <int> one = new RWList <int>(); one.Add(3);
            RWList <int> two = one.Clone();       two.Add(2);
            RWList <int> thr = two.Clone();       thr.Add(1);

            ExpectList(thr, 3, 2, 1);

            ExpectList(one.Select(delegate(int i) { return(i + 1); }), 4);
            ExpectList(two.Select(delegate(int i) { return(i + 1); }), 4, 3);
            ExpectList(thr.Select(delegate(int i) { return(i + 1); }), 4, 3, 2);
            ExpectList(two.Select(delegate(int i) { return(i == 3 ? 3 : 0); }), 3, 0);
            ExpectList(thr.Select(delegate(int i) { return(i == 3 ? 3 : 0); }), 3, 0, 0);
            ExpectList(thr.Select(delegate(int i) { return(i == 1 ? 0 : i); }), 3, 2, 0);

            Assert.That(one.SmartSelect(delegate(int i) { return(i); }).ToRVList() == one.ToRVList());
            Assert.That(two.SmartSelect(delegate(int i) { return(i); }).ToRVList() == two.ToRVList());
            Assert.That(thr.SmartSelect(delegate(int i) { return(i); }).ToRVList() == thr.ToRVList());
            ExpectList(one.SmartSelect(delegate(int i) { return(i + 1); }), 4);
            ExpectList(two.SmartSelect(delegate(int i) { return(i + 1); }), 4, 3);
            ExpectList(thr.SmartSelect(delegate(int i) { return(i + 1); }), 4, 3, 2);
            ExpectList(two.SmartSelect(delegate(int i) { return(i == 3 ? 3 : 0); }), 3, 0);
            ExpectList(thr.SmartSelect(delegate(int i) { return(i == 3 ? 3 : 0); }), 3, 0, 0);
            ExpectList(thr.SmartSelect(delegate(int i) { return(i == 1 ? 0 : i); }), 3, 2, 0);
            Assert.That(thr.SmartSelect(delegate(int i) { return(i == 1 ? 0 : i); }).WithoutLast(1) == thr.WithoutLast(1));
        }