Пример #1
0
        public void TupleTest()
        {
            bool             isExecuted1 = false;
            ValueTuple <int> tuple       = new ValueTuple <int>(0);
            Func <int, int>  addOne      = x => { isExecuted1 = true; return(x + 1); };

            ValueTuple <int> query1 = from x in tuple select addOne(x); // Execution.

            Assert.IsTrue(isExecuted1);                                 // Immediate execution.

            Assert.AreEqual(0 + 1, query1.Item1);
            Assert.IsTrue(isExecuted1);

            // Functor law 1: F.Select(Id) == Id(F)
            Assert.AreEqual(tuple.Select(Functions.Id).Item1, Functions.Id(tuple).Item1);
            // Functor law 2: F.Select(f2.o(f1)) == F.Select(f1).Select(f2)
            Func <int, string>  addTwo = x => (x + 2).ToString(CultureInfo.InvariantCulture);
            ValueTuple <string> query2 = tuple.Select(addTwo.o(addOne));
            ValueTuple <string> query3 = tuple.Select(addOne).Select(addTwo);

            Assert.AreEqual(query2.Item1, query3.Item1);
        }