Exemplo n.º 1
0
        public void TestWhere()
        {
            var q = new QueriableDummy <ntup>();
            var r = from d in q
                    where d.run > 10
                    select d;
            var c = r.Count();

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");
            var res = DummyQueryExectuor.FinalResult;

            res.DumpCodeToConsole();

            ///
            /// We expect a single top level statement
            ///

            Assert.AreEqual(1, res.CodeBody.Statements.Count(), "only single statement expected");
            var ifStatement = res.CodeBody.Statements.First() as StatementFilter;

            Assert.IsNotNull(ifStatement, "if statement isn't an if statement!");
            Assert.AreEqual("((*this).run)>10", ifStatement.TestExpression.RawValue, "incorrect if statement");

            ///
            /// Finally, the count statement should be down here!
            ///

            Assert.AreEqual(1, ifStatement.Statements.Count(), "expected a single statement inside the if statemenet!");
            Assert.IsInstanceOfType(ifStatement.Statements.First(), typeof(StatementAggregate), "incorrect if statement");
        }
Exemplo n.º 2
0
        public void TestSingleTopLevelQuery()
        {
            var q      = new QueriableDummy <ntup>();
            var result = from d in q
                         select d;
            var c = result.Count();

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");

            /// Return type is correct
            Assert.IsNotNull(DummyQueryExectuor.FinalResult.ResultValue, "Expected a result from the count!");
            Assert.AreEqual(DummyQueryExectuor.FinalResult.ResultValue.Type, typeof(int), "integer return type expected");

            var res = DummyQueryExectuor.FinalResult;

            ///
            /// Now, take a lok at the statements and make sure that we see them all correctly.
            ///

            Assert.AreEqual(1, res.CodeBody.Statements.Count(), "incorrect # of statements");
            var statement = res.CodeBody.Statements.First();

            Assert.IsInstanceOfType(statement, typeof(StatementAggregate), "count should be incrementing an integer!");
            Assert.AreEqual(DummyQueryExectuor.FinalResult.ResultValue, (statement as StatementAggregate).ResultVariable, "The variable should match");
        }
Exemplo n.º 3
0
        public void TestDuplicateDelc()
        {
            // A crash that happened in one of my seperate programs...

            var q         = new QueriableDummy <CollectionTree>();
            var particles = from evt in q
                            select(from i_p in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                                   let px         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px[i_p]
                                   let py         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_py[i_p]
                                   let pz         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pz[i_p]
                                   let m          = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_m[i_p]
                                   let pdgid      = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pdgId[i_p]
                                   let vtxInitBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx[i_p]
                                   let vtxTermBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_endVtx[i_p]
                                   let vtxInitIdx = FindVertexFromBC.Invoke(evt, vtxInitBC)
                                   let vtxTermIdx = FindVertexFromBC.Invoke(evt, vtxTermBC)
                                   select new ParticleInfo
            {
                PDGID   = pdgid,
                vtxInit = VertexVector.Invoke(evt, vtxInitIdx),
                vtxTerm = VertexVector.Invoke(evt, vtxTermIdx)
            });

            var prs = particles.SelectMany(p => p)
                      .Where(p => p.vtxTerm.Px() > 6.0)
                      .Where(p => p.vtxTerm.Pt() > 5.0)
                      .Count();
            var query = DummyQueryExectuor.FinalResult;

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());
        }
Exemplo n.º 4
0
        public void TestComplexDeclaresTwice()
        {
            // Silently produces multiply declared variables - only warnings on the Linux complers. :(

            var q         = new QueriableDummy <CollectionTree>();
            var particles = from evt in q
                            select(from i_p in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                                   let px         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px[i_p]
                                   let py         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_py[i_p]
                                   let pz         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pz[i_p]
                                   let m          = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_m[i_p]
                                   let pdgid      = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pdgId[i_p]
                                   let vtxInitBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx[i_p]
                                   let vtxTermBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_endVtx[i_p]
                                   let vtxInitIdx = FindVertexFromBC.Invoke(evt, vtxInitBC)
                                   let vtxTermIdx = FindVertexFromBC.Invoke(evt, vtxTermBC)
                                   select new ParticleInfo
            {
                PDGID   = pdgid,
                vtxInit = VertexVector.Invoke(evt, vtxInitIdx),
                vtxTerm = VertexVector.Invoke(evt, vtxTermIdx)
            });

            var prs   = particles.SelectMany(p => p).Where(p => p.vtxTerm.Mag() > 1.0).Count();
            var query = DummyQueryExectuor.FinalResult;

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());
        }
Exemplo n.º 5
0
        public void TestJoinOnTClonesObjectWithNestedFunctionCall()
        {
            var q = new QueriableDummy <CollectionTree>();

            Expression <Func <CollectionTree, int, int> > finder = (evt, particleIndex) =>
                                                                   Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_barcode.Length)
                                                                   .Where(i => evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx[particleIndex] == evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_barcode[i])
                                                                   .FirstOrDefault();

            Expression <Func <CollectionTree, int, ROOTNET.NTVector3> > vertexPostion =
                (evt, i) => new ROOTNET.NTVector3(
                    evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_x[i],
                    evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_y[i],
                    evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_z[i]
                    );

            var pvPairs = from evt in q
                          from pindex in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx.Length)
                          let idx = finder.Invoke(evt, pindex)
                                    select vertexPostion.Invoke(evt, idx);

            var r     = pvPairs.Where(i => i.Mag() > 4).Count();
            var query = DummyQueryExectuor.FinalResult;

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());

            Assert.AreEqual(1, query.CodeBody.Statements.Count(), "# of statements");
            var scnd = query.CodeBody.Statements.First() as IBookingStatementBlock;

            Assert.IsNotNull(scnd, "Booking block fro 2nd statement");
            Assert.AreEqual(6, scnd.Statements.Count(), "# of statements in second for loop");
        }
Exemplo n.º 6
0
        public void TestTempVarNullComparisonShouldExplode()
        {
            // A crash that happened in one of my seperate programs...

            var q         = new QueriableDummy <CollectionTree>();
            var particles = from evt in q
                            select(from i_p in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                                   let px         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px[i_p]
                                   let py         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_py[i_p]
                                   let pz         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pz[i_p]
                                   let m          = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_m[i_p]
                                   let pdgid      = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pdgId[i_p]
                                   let vtxInitBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx[i_p]
                                   let vtxTermBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_endVtx[i_p]
                                   let vtxInitIdx = FindVertexFromBC.Invoke(evt, vtxInitBC)
                                   let vtxTermIdx = FindVertexFromBC.Invoke(evt, vtxTermBC)
                                   select new ParticleInfo
            {
                PDGID   = pdgid,
                vtxInit = VertexVector.Invoke(evt, vtxInitIdx),
                vtxTerm = VertexVector.Invoke(evt, vtxTermIdx)
            });

            var prs = particles.SelectMany(p => p).Where(p => p.vtxTerm != null).Count();
        }
Exemplo n.º 7
0
        public void TestJoinOnTClonesObjectWithEnumerableExplicit()
        {
            var q = new QueriableDummy <CollectionTree>();

            var particles = from evt in q
                            select new
            {
                Particles = from pindex in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                            let vtxInitBC = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx[pindex]
                                            where vtxInitBC < 0
                                            let vtxInitIndex = (from vindex in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_barcode.Length)
                                                                where evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_barcode[vindex] == vtxInitBC
                                                                select vindex).FirstOrDefault()
                                                               select new
                {
                    Px     = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px[pindex],
                    Py     = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_py[pindex],
                    PInitX = evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_x[vtxInitIndex]
                }
            };
            var r     = particles.Where(plst => plst.Particles.Any(p => p.PInitX > 0)).Count();
            var query = DummyQueryExectuor.FinalResult;

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());
            // Make sure we don't throw here.
        }
Exemplo n.º 8
0
        public void TestJoinOnTClonesObjectWithEnumerable()
        {
            var q = new QueriableDummy <CollectionTree>();

            var particles = from evt in q
                            select new
            {
                Particles = from pindex in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                            join vindex in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_x.Length)
                            on evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx[pindex] equals evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_barcode[vindex] into productionVertexList
                            where productionVertexList.Count() == 1
                            let vtxInitIndex = productionVertexList.First()
                                               select new
                {
                    Px     = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px[pindex],
                    Py     = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_py[pindex],
                    PInitX = evt.McEventCollection_p4_GEN_EVENT.m_genVertices.m_x[vtxInitIndex]
                }
            };
            var r     = particles.Where(plst => plst.Particles.Any(p => p.PInitX > 0)).Count();
            var query = DummyQueryExectuor.FinalResult;

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());
        }
Exemplo n.º 9
0
        public void TestQueryOnTClonesObjectWithEnumerableAndLenghtCombineR()
        {
            var q = new QueriableDummy <CollectionTree>();

            var r1 = from evt in q
                     from pindex in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                     select pindex;
            var r      = r1.Count();
            var query1 = DummyQueryExectuor.FinalResult;

            var r2 = from evt in q
                     from p in evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px
                     select p;

            r = r2.Count();
            var query2 = DummyQueryExectuor.FinalResult;

            var query = CombineQueries(query2, query1);

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());

            Assert.AreEqual(1, query.QueryCode().Count(), "# fo code blocks");
            Assert.AreEqual(2, query.QueryCode().First().Statements.Count(), "# statements in the code body");
            var forblock2 = query.QueryCode().First().Statements.First() as IBookingStatementBlock;

            Assert.IsNotNull(forblock2, "2nd for block");
            Assert.AreEqual(1, forblock2.Statements.Count(), "# of for #2 statement statements");
        }
Exemplo n.º 10
0
        public void TestQueryOnTClonesObjectWithEnumerableAndLenghtCombine()
        {
            var q = new QueriableDummy <CollectionTree>();

            var r1 = from evt in q
                     from pindex in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                     select pindex;
            var r      = r1.Count();
            var query1 = DummyQueryExectuor.FinalResult;

            Console.WriteLine("The QM for the first query is  {0}.", DummyQueryExectuor.LastQueryModel.ToString());

            var r2 = from evt in q
                     from p in evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px
                     select p;

            r = r2.Count();
            var query2 = DummyQueryExectuor.FinalResult;

            Console.WriteLine("The QM for the second query is  {0}.", DummyQueryExectuor.LastQueryModel.ToString());

            var query = CombineQueries(query1, query2);

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());

            Assert.AreEqual(1, query.QueryCode().Count(), "# fo code blocks");
            Assert.AreEqual(1, query.QueryCode().First().Statements.Count(), "# statements in the code body");
            var forblock2 = query.QueryCode().First().Statements.First() as IBookingStatementBlock;

            Assert.IsNotNull(forblock2, "2nd for block");
            Assert.AreEqual(2, forblock2.Statements.Count(), "# of for #2 statement statements");

            Assert.Inconclusive("It seems the result of the function is never used");
        }
Exemplo n.º 11
0
        public void TestQueryOnTClonesObjectCombine()
        {
            var q = new QueriableDummy <CollectionTree>();

            var r1 = from evt in q
                     from p in evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px
                     select p;
            var r      = r1.Count();
            var query1 = DummyQueryExectuor.FinalResult;

            r = r1.Count();
            var query2 = DummyQueryExectuor.FinalResult;

            var query = CombineQueries(query1, query2);

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());

            Assert.AreEqual(1, query.QueryCode().Count(), "# of query blocks");
            var qu = query.QueryCode().First();

            Assert.AreEqual(1, qu.Statements.Count(), "# statements in the code body");
            var forblock = qu.Statements.First() as IBookingStatementBlock;

            Assert.IsNotNull(forblock, "top level statement");
            Assert.AreEqual(2, forblock.Statements.Count(), "# of statements in the code");
        }
Exemplo n.º 12
0
        public void PrettyPrintSimpleQuery()
        {
            var q = new QueriableDummy <ntup>();

            var r = q.Select(rq => rq.run * 2).PrettyPrintQuery();

            Console.WriteLine(r);
            Assert.IsTrue(r.Contains("select"));
            Assert.IsTrue(r.Contains("[rq].run * 2"));
        }
Exemplo n.º 13
0
        public void PrettyPrintHideTuples()
        {
            var q = new QueriableDummy <ntup>();

            var r = q.Select(rq => Tuple.Create(rq.run * 2, 1)).Select(rq => rq.Item1).PrettyPrintQuery();

            Console.WriteLine(r);
            Assert.IsFalse(r.Contains("Tuple"));
            Assert.IsTrue(r.Contains("[rq].run * 2"));
        }
Exemplo n.º 14
0
        public void PrettyPrintComplexQueryII()
        {
            var q = new QueriableDummy <dummyntup>();

            var r = from e in q
                    let rf = (from s in e.valC1D where s > 22 select s * 2).Sum()
                             where rf > 20
                             select e.run;

            var sr = r.PrettyPrintQuery();

            Console.WriteLine(sr);
        }
Exemplo n.º 15
0
        public void TestBasicUniqueCombo()
        {
            var q       = new QueriableDummy <ntupArray>();
            var results = from evt in q
                          select evt.run.PairWiseAll((r1, r2) => r1 != r2).Count();

            var total = results.Aggregate(0, (seed, val) => seed + val);

            //var total = results.Count();

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "expecing some code to have been generated");
            DummyQueryExectuor.FinalResult.DumpCodeToConsole();
        }
Exemplo n.º 16
0
        public void TestDoubleNestedQuery()
        {
            var q      = new QueriableDummy <ntup>();
            var result = from d in q
                         from m in d.other
                         from r in m.deeper
                         select d;
            var c = result.Count();

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");

            /// Return type is correct
            Assert.IsNotNull(DummyQueryExectuor.FinalResult.ResultValue, "Expected a result from the count!");
            Assert.AreEqual(DummyQueryExectuor.FinalResult.ResultValue.Type, typeof(int), "integer return type expected");

            var res = DummyQueryExectuor.FinalResult;

            ///
            /// We should be booking "d" as a variable that hangs out for a while at the top level
            ///

            Assert.AreEqual(0, res.CodeBody.DeclaredVariables.Count(), "expected one variable declared");

            ///
            /// Now, take a lok at the statements and make sure that we see them all correctly. This first guy should be the
            /// loop statement over the d.other guys.
            ///

            Assert.AreEqual(1, res.CodeBody.Statements.Count(), "Expected a single statement");
            Assert.IsInstanceOfType(res.CodeBody.Statements.First(), typeof(IBookingStatementBlock), "loop missing!");

            var loop = res.CodeBody.Statements.First() as IBookingStatementBlock;

            ///
            /// Second level down...
            ///

            Assert.AreEqual(1, loop.Statements.Count(), "expected second level down one loop statement");
            Assert.IsInstanceOfType(loop.Statements.First(), typeof(IBookingStatementBlock), "Expected 2nd level loop");

            var loop2 = loop.Statements.First() as IBookingStatementBlock;

            ///
            /// And below that should be one statement that does the incrementing
            ///

            Assert.AreEqual(1, loop2.Statements.Count(), "incorrect # of statements");
            var statement = loop2.Statements.First();

            Assert.IsInstanceOfType(statement, typeof(StatementAggregate), "count should be incrementing an integer!");
        }
Exemplo n.º 17
0
        public void PrettyPrintComplexQueryI()
        {
            var q = new QueriableDummy <dummyntup>();

            var r = from e in q
                    from s in e.valC1D
                    where s > 22
                    select s * 2;

            var sr = r.PrettyPrintQuery();

            Console.WriteLine(sr);
            Assert.AreEqual(4, CountLines(sr));
        }
Exemplo n.º 18
0
        public void TestQueryWithTwoRangeVariablesNamedSameThing()
        {
            var q       = new QueriableDummy <ntup>();
            var result1 = from evt in q
                          where evt.run > 5
                          select evt;
            var result2 = from evt in result1
                          where evt.run > 10
                          select evt;
            var c = result2.Count();

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");
            DummyQueryExectuor.FinalResult.DumpCodeToConsole();

            /// Looking for an infinite loop!
        }
Exemplo n.º 19
0
        public void TestAggregateWithHistogram()
        {
            var q = new QueriableDummy <ntup>();
            var r = from d in q
                    select d;
            var c = r.ApplyToObject(new ROOTNET.NTH1F("dude", "put a fork in it", 10, 0.0, 20.0), (h1, n1) => h1.Fill(n1.run));

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");
            var res = DummyQueryExectuor.FinalResult;

            Assert.AreEqual(res.ResultValue.Type, typeof(ROOTNET.NTH1F), "incorrect result type came back!");
            var varToTrans = res.VariablesToTransfer.ToArray();

            Assert.AreEqual(1, varToTrans.Length, "variables to transfer incorrect");
            Assert.IsInstanceOfType(varToTrans[0], typeof(KeyValuePair <string, object>), "bad object type to transfer");
        }
Exemplo n.º 20
0
        public void TestAnonDirectCompareObjects()
        {
            var q    = new QueriableDummy <ntupArray>();
            var anon = from evt in q
                       select(from r in evt.run
                              select new
            {
                Value = r
            });

            var results = from evt in anon
                          select evt.PairWiseAll((r1, r2) => r1 != r2).Count();

            var tot = results.Aggregate(0, (seed, val) => seed + val);

            DummyQueryExectuor.FinalResult.DumpCodeToConsole();
        }
Exemplo n.º 21
0
        public void TestBasicUniqueComboCheckItemAccess()
        {
            var q      = new QueriableDummy <ntupArray>();
            var combos = from evt in q
                         select(from cmb in evt.run.PairWiseAll((r1, r2) => r1 != r2)
                                select cmb).Aggregate(0, (seed, val) => seed + val);

            var arg = combos.Aggregate(0, (seed, val) => seed + val);

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "expecing some code to have been generated");
            DummyQueryExectuor.FinalResult.DumpCodeToConsole();

            var res = DummyQueryExectuor.FinalResult.ResultValue;

            Assert.IsNotNull(res, "final result");
            Assert.AreEqual(typeof(int), res.Type, "final result type");
        }
Exemplo n.º 22
0
        public void TestSimpleLoopAndFilterCombine()
        {
            const int numberOfIter = 25;
            var       rootFile     = TestUtils.CreateFileOfVectorInt(numberOfIter);

            ///
            /// Get a simple query we can "play" with. That this works
            /// depends on each event having 10 entries in the array, which contains
            /// the numbers 0-10.
            ///

            var q      = new QueriableDummy <TestUtils.TestNtupeArr>();
            var dudeQ1 = from evt in q
                         where (evt.myvectorofint.Max() > 5)
                         select evt;
            var dude1  = dudeQ1.Count();
            var query1 = DummyQueryExectuor.LastQueryModel;

            var dudeQ2 = from evt in q
                         where (evt.myvectorofint.Max() > 5)
                         select evt;
            var dude2  = dudeQ2.Count();
            var query2 = DummyQueryExectuor.LastQueryModel;

            //
            // Convert to future's
            //

            var exe      = new TTreeQueryExecutor(new Uri[] { rootFile }, "dude", typeof(ntuple), typeof(TestUtils.TestNtupeArr));
            var q1future = exe.ExecuteScalarAsFuture <int>(query1);
            var q2future = exe.ExecuteScalarAsFuture <int>(query2);

            //
            // Run them!
            //

            exe.ExecuteQueuedQueries().Wait();

            //
            // And check
            //

            Assert.AreEqual(q1future.Value, numberOfIter);
            Assert.AreEqual(q2future.Value, numberOfIter);
        }
Exemplo n.º 23
0
        public void TestResolveSubExpression()
        {
            var q       = new QueriableDummy <LINQToTTreeLib.QueryVisitorTest.NtupWithObjects>();
            var result1 = from evt in q
                          where (from jet in evt.jets where jet.var1 > 1.0 select jet).Count() == 1
                          select evt;
            var c = result1.Count();

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");
            DummyQueryExectuor.FinalResult.DumpCodeToConsole();

            // Extract the code and count the number of loops. There should be just one for that "where" sub-expression.

            Assert.AreEqual(1, DummyQueryExectuor.FinalResult.Functions.Count(), "# of functions");
            var code      = DummyQueryExectuor.FinalResult.Functions.First().StatementBlock.Statements;
            var loopCount = code.Where(s => s is StatementForLoop).Count();

            Assert.AreEqual(1, loopCount, "# of loops incorrect");
        }
Exemplo n.º 24
0
        public void TestSimpleSum()
        {
            var q = new QueriableDummy <ntup>();
            var s = q.Sum(i => i.run);

            var result = DummyQueryExectuor.FinalResult;

            result.DumpCodeToConsole();

            //
            // Look for the assignment operator in the loop
            //

            var toplevel = result.CodeBody.Statements;
            var assign   = toplevel.First() as LINQToTTreeLib.Statements.StatementAssign;

            Assert.IsNotNull(assign, "Assign statement missing");

            Assert.IsTrue(assign.Expression.RawValue.Contains("+"), "the plus sign is missing");
        }
Exemplo n.º 25
0
        public void TestQueryOnNonTClonesObject()
        {
            var q = new QueriableDummy <CollectionTree>();

            var r1 = from evt in q
                     from p in evt.EventInfo_p3_McEventInfo.m_AllTheData
                     select p;
            var r = r1.Count();

            var query1 = DummyQueryExectuor.FinalResult;

            query1.DumpCodeToConsole();
            CheckSingleDecl(query1.DumpCode());

            Assert.AreEqual(1, query1.CodeBody.Statements.Count(), "# statements in the code body");
            var forblock = query1.CodeBody.Statements.First() as IBookingStatementBlock;

            Assert.IsNotNull(forblock, "top level statement");
            Assert.AreEqual(1, forblock.Statements.Count(), "# of statements in the code");
        }
Exemplo n.º 26
0
        public void TestInlineIfWithGoodTest()
        {
            // A crash that happened in one of my seperate programs...

            var q         = new QueriableDummy <CollectionTree>();
            var particles = from evt in q
                            select(from i_p in Enumerable.Range(0, evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px.Length)
                                   let px         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_px[i_p]
                                   let py         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_py[i_p]
                                   let pz         = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pz[i_p]
                                   let m          = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_m[i_p]
                                   let pdgid      = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_pdgId[i_p]
                                   let vtxInitBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_prodVtx[i_p]
                                   let vtxTermBC  = evt.McEventCollection_p4_GEN_EVENT.m_genParticles.m_endVtx[i_p]
                                   let vtxInitIdx = FindVertexFromBC.Invoke(evt, vtxInitBC)
                                   let vtxTermIdx = FindVertexFromBC.Invoke(evt, vtxTermBC)
                                   select new ParticleInfo
            {
                PDGID     = pdgid,
                vtxInitOK = vtxInitBC != 0,
                vtxTermOK = vtxTermBC != 0,
                vtxInit   = VertexVectorQ.Invoke(evt, vtxInitIdx),
                vtxTerm   = VertexVectorQ.Invoke(evt, vtxTermIdx)
            });

            var prs   = particles.SelectMany(p => p).Where(p => p.vtxTermOK).Where(p => p.vtxTerm.Mag() > 1.0).Count();
            var query = DummyQueryExectuor.FinalResult;

            query.DumpCodeToConsole();
            CheckSingleDecl(query.DumpCode());

            // We want to make sure that the vtxTerm stuff is not evaluated unless the vtxTermOK passes first...
            Assert.AreEqual(1, DummyQueryExectuor.FinalResult.CodeBody.Statements.Count(), "# of statements in top level loop");
            var topLevelLoop = DummyQueryExectuor.FinalResult.CodeBody.Statements.First() as LINQToTTreeLib.Statements.StatementForLoop;

            Assert.IsNotNull(topLevelLoop, "Top level loop isn't right");
            Assert.AreEqual(1, topLevelLoop.Statements.Count(), "# of statements in the top level block are incorrect");
            var ifStatement = topLevelLoop.Statements.First() as LINQToTTreeLib.Statements.StatementFilter;

            Assert.IsNotNull(ifStatement, "If statement first in the for loop");
        }
Exemplo n.º 27
0
        public void TestQueryOnNonTClonesObjectCombine()
        {
            var q = new QueriableDummy <CollectionTree>();

            var r1 = from evt in q
                     from p in evt.EventInfo_p3_McEventInfo.m_AllTheData
                     select p;
            var r      = r1.Count();
            var query1 = DummyQueryExectuor.FinalResult;
            var r2     = r1.Count();
            var query2 = DummyQueryExectuor.FinalResult;

            Console.WriteLine("Query1:");
            Console.WriteLine();
            query1.DumpCodeToConsole();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Query2:");
            Console.WriteLine();
            query2.DumpCodeToConsole();

            var query = CombineQueries(query1, query2);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Combined Query:");
            Console.WriteLine();
            query.DumpCodeToConsole();

            // Check
            CheckSingleDecl(query.DumpCode());

            Assert.AreEqual(1, query.QueryCode().Count(), "# of query code blocks");
            Assert.AreEqual(1, query.QueryCode().First().Statements.Count(), "# statements in the code body");
            var forblock = query.QueryCode().First().Statements.First() as IBookingStatementBlock;

            Assert.IsNotNull(forblock, "top level statement");
            Assert.AreEqual(2, forblock.Statements.Count(), "# of statements in the code");
        }
Exemplo n.º 28
0
        public void TestSimpleAggregate()
        {
            var q = new QueriableDummy <ntup>();
            var r = from d in q
                    select d;
            var c = r.Aggregate(1, (count, n) => count + 1);

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");
            var res = DummyQueryExectuor.FinalResult;

            /// For this there should be one statement - the addition statement for the variable.

            Assert.AreEqual(1, res.CodeBody.Statements.Count(), "not right number of statements coming back!");
            Assert.IsInstanceOfType(res.CodeBody.Statements.First(), typeof(StatementAggregate), "Assignment doesn't seem to be there");

            var           assignment = res.CodeBody.Statements.First() as StatementAggregate;
            StringBuilder bld        = new StringBuilder();

            bld.AppendFormat("{0}+1", assignment.ResultVariable.ParameterName, "bad assignment!");
            Assert.AreEqual(bld.ToString(), assignment.Expression.RawValue, "expression is incorrect");
        }
Exemplo n.º 29
0
        public void TestScope()
        {
            // Make sure that if anything funky needs to be done outside our loop,
            // it gets declared correctly.

            var q       = new QueriableDummy <ntupArray>();
            var results = from evt in q
                          select evt.run.PairWiseAll((r1, r2) => CPPHelperFunctions.Calc(r1) != r2).Count();

            var total = results.Aggregate(0, (seed, val) => seed + val);

            DummyQueryExectuor.FinalResult.DumpCodeToConsole();

            //
            // The *2 should be burried in the loop. However, we've seen it popped up to the top
            // in a bug. So test for that regression.
            //

            var seen2 = DummyQueryExectuor.FinalResult.CodeBody.Statements.Where(s => s is StatementSimpleStatement).Cast <StatementSimpleStatement>().Where(s => s.ToString().Contains("]*2")).Any();

            Assert.IsFalse(seen2, "Saw a ']*2' in a top level code statement!");
        }
Exemplo n.º 30
0
        public void TestWhereTwoClauses()
        {
            var q = new QueriableDummy <ntup>();
            var r = from d in q
                    where d.run > 10 && d.run < 100
                    select d;
            var c = r.Count();

            Assert.IsNotNull(DummyQueryExectuor.FinalResult, "Expecting some code to have been generated!");
            var res = DummyQueryExectuor.FinalResult;

            res.DumpCodeToConsole();

            ///
            /// We expect a single top level statement
            ///

            var assStatement = res.CodeBody.Statements.First() as StatementAssign;

            Assert.IsNotNull(assStatement, "if statement isn't an if statement!");
            Assert.AreEqual("((*this).run)>10", assStatement.Expression.RawValue, "incorrect if statement");
        }