Exemple #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);
        }
Exemple #2
0
        private static bool SimplePartitionMergeWhereScanTest1(int dataSize, int partitions, bool pipeline)
        {
            TestHarness.TestLog("SimplePartitionMergeWhereScanTest1: {0}, {1}, {2}", dataSize, partitions, pipeline);

            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

            IEnumerator <int> stream = whereOp.GetEnumerator();

            int count = 0;

            while (stream.MoveNext())
            {
                // @TODO: verify all the elements we expected are present.
                count++;
            }

            bool passed = count == (dataSize / 2);

            TestHarness.TestLog("  > count == dataSize/2? i.e. {0} == {1}? {2}", count, dataSize / 2, passed);
            return(passed);
        }
Exemple #3
0
        private static bool SimplePartitionMergeWhereScanTest1(int dataSize, int partitions, bool pipeline)
        {
            TestHarness.TestLog("SimplePartitionMergeWhereScanTest1: {0}, {1}, {2}", dataSize, partitions, pipeline);

            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

            IEnumerator<int> stream = whereOp.GetEnumerator();

            int count = 0;
            while (stream.MoveNext())
            {
                // @TODO: verify all the elements we expected are present.
                count++;
            }

            bool passed = count == (dataSize / 2);
            TestHarness.TestLog("  > count == dataSize/2? i.e. {0} == {1}? {2}", count, dataSize/2, passed);
            return passed;
        }
Exemple #4
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;
        }