Example #1
0
        private static bool CheckWhereSelectComposition(int dataSize)
        {
            TestHarness.TestLog("CheckWhereSelectComposition: {0}", dataSize);

            int[] data = new int[dataSize];
            for (int i = 0; i < dataSize; i++)
            {
                data[i] = i;
            }

            WhereQueryOperator <int> whereOp = new WhereQueryOperator <int>(
                data, delegate(int x) { return((x % 2) == 0); }); // select only even elements
            SelectQueryOperator <int, int> selectOp = new SelectQueryOperator <int, int>(
                whereOp, delegate(int x) { return(x * 2); });     // just double the elements

            bool passed = true;

            // Verify composition of the tree:
            //     SELECT <-- WHERE <-- SCAN <-- {data}

            SelectQueryOperator <int, int> sel = selectOp as SelectQueryOperator <int, int>;

            passed &= sel != null;
            TestHarness.TestLog("  > {0}: SELECT is non-null", passed);

            WhereQueryOperator <int> where = sel.Child as WhereQueryOperator <int>;
            passed &= where != null;
            TestHarness.TestLog("  > {0}: WHERE is non-null", passed);

            ScanQueryOperator <int> scan = where.Child as ScanQueryOperator <int>;

            passed &= scan != null;
            TestHarness.TestLog("  > {0}: SCAN is non-null", passed);

            // Now verify the output is what we expect.

            int expectSum = 0;

            for (int i = 0; i < dataSize; i++)
            {
                if ((i % 2) == 0)
                {
                    expectSum += (i * 2);
                }
            }

            int realSum         = 0;
            IEnumerator <int> e = selectOp.GetEnumerator();

            while (e.MoveNext())
            {
                realSum += e.Current;
            }

            passed = (realSum == expectSum);

            TestHarness.TestLog("  > {0}: actual sum {1} == expected sum {2}?", passed, realSum, expectSum);

            return(passed);
        }
Example #2
0
        private static bool CheckWhereSelectComposition(int dataSize)
        {
            TestHarness.TestLog("CheckWhereSelectComposition: {0}", dataSize);

            int[] data = new int[dataSize];
            for (int i = 0; i < dataSize; i++) data[i] = i;

            WhereQueryOperator<int> whereOp = new WhereQueryOperator<int>(
                data, delegate(int x) { return (x % 2) == 0; }); // select only even elements
            SelectQueryOperator<int, int> selectOp = new SelectQueryOperator<int, int>(
                whereOp, delegate(int x) { return x * 2; }); // just double the elements

            bool passed = true;

            // Verify composition of the tree:
            //     SELECT <-- WHERE <-- SCAN <-- {data}

            SelectQueryOperator<int, int> sel = selectOp as SelectQueryOperator<int, int>;
            passed &= sel != null;
            TestHarness.TestLog("  > {0}: SELECT is non-null", passed);

            WhereQueryOperator<int> where = sel.Child as WhereQueryOperator<int>;
            passed &= where != null;
            TestHarness.TestLog("  > {0}: WHERE is non-null", passed);

            ScanQueryOperator<int> scan = where.Child as ScanQueryOperator<int>;
            passed &= scan != null;
            TestHarness.TestLog("  > {0}: SCAN is non-null", passed);

            // Now verify the output is what we expect.

            int expectSum = 0;
            for (int i = 0; i < dataSize; i++)
                if ((i % 2) == 0)
                    expectSum += (i * 2);

            int realSum = 0;
            IEnumerator<int> e = selectOp.GetEnumerator();
            while (e.MoveNext())
            {
                realSum += e.Current;
            }

            passed = (realSum == expectSum);

            TestHarness.TestLog("  > {0}: actual sum {1} == expected sum {2}?", passed, realSum, expectSum);          

            return passed;
        }