Пример #1
0
        public void TestChangeScopeSpecificNextLevel()
        {
            GeneratedCode target = new GeneratedCode();

            target.Add(new StatementInlineBlock());
            IStatement s = new StatementInlineBlock();

            var deepestStatementLevel = TestUtils.GetDeepestStatementLevel(target);
            var deepestDeclarLevel    = TestUtils.GetDeepestBookingLevel(target);

            var currentS = target.CurrentScope;

            var curVars       = deepestDeclarLevel.DeclaredVariables.Count();
            var curStatements = deepestStatementLevel.Statements.Count();
            var v1            = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            target.Add(v1);
            target.Add(s);

            target.CurrentScope = currentS;

            var v2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            target.Add(v2);
            s.Parent = null;
            target.Add(s);
            Assert.AreEqual(curStatements + 2, deepestStatementLevel.Statements.Count(), "Scope reset, should always be two extra statements here!");
            Assert.AreEqual(curVars + 2, deepestDeclarLevel.DeclaredVariables.Count(), "Scope reset should have also reset where the variable was pointing");
        }
Пример #2
0
        public void TestForFunctionNumber()
        {
            CPPTranslator target = new CPPTranslator();
            var           vInt   = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();

            code.SetResult(vInt);

            var innerBlock = new StatementInlineBlock();
            var vInt2      = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt2.SetInitialValue("5");
            innerBlock.Add(vInt2);
            code.Add(innerBlock);

            var r = TranslateGeneratedCode(target, code);

            Assert.IsTrue(r.ContainsKey("NumberOfQueryFunctions"), "Number of functions isn't here");
            Assert.IsInstanceOfType(r["NumberOfQueryFunctions"], typeof(int), "# function type");
            Assert.AreEqual(1, r["NumberOfQueryFunctions"], "# of functions");

            Assert.IsTrue(r.ContainsKey("QueryFunctionBlocks"), "Missing query function blocks");
            Assert.IsInstanceOfType(r["QueryFunctionBlocks"], typeof(IEnumerable <IEnumerable <string> >), "Type is incorrect");
            var codeBlocks = r["QueryFunctionBlocks"] as IEnumerable <IEnumerable <string> >;

            Assert.AreEqual(1, codeBlocks.Count(), "Wrong number of code blocks");
        }
Пример #3
0
        public void TestObjectInitalizerInInnerBlock()
        {
            CPPTranslator target = new CPPTranslator();
            var           vInt   = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();

            code.SetResult(vInt);

            var innerBlock = new StatementInlineBlock();
            var vInt2      = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            vInt2.SetInitialValue("5");
            innerBlock.Add(vInt2);
            innerBlock.Add(new StatementSimpleStatement("fork = dork"));
            code.Add(innerBlock);

            var r = TranslateGeneratedCode(target, code);

            var st = (r["QueryFunctionBlocks"] as IEnumerable <IEnumerable <string> >).First().ToArray();

            Assert.AreEqual(6, st.Length, "incorrect number of statements");
            Assert.AreEqual("int " + vInt2.RawValue + " = 5;", st[2].Trim(), "incorrect initialization");
        }
Пример #4
0
        public void TestResultScopeCurrentScope()
        {
            var gc = new GeneratedCode();
            var b1 = new StatementInlineBlock();

            gc.Add(b1);
            gc.SetCurrentScopeAsResultScope();
            var outterScope = gc.CurrentScope;

            var b2 = new StatementInlineBlock();

            gc.Add(b2);
            gc.SetCurrentScopeAsResultScope();

            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));

            Assert.AreEqual(0, b1.DeclaredVariables.Count(), "variables at outside loop after 0 add");
            Assert.AreEqual(1, b2.DeclaredVariables.Count(), "variables at inner loop after 1 add");

            gc.CurrentScope = outterScope;

            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));

            Assert.AreEqual(1, b1.DeclaredVariables.Count(), "variables at outside loop after 1 add");
            Assert.AreEqual(1, b2.DeclaredVariables.Count(), "variables at inner loop after 2 add");
        }
Пример #5
0
        public void TestForFunctionNumber()
        {
            CPPTranslator target = new CPPTranslator();
            var vInt = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();
            code.SetResult(vInt);

            var innerBlock = new StatementInlineBlock();
            var vInt2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt2.SetInitialValue("5");
            innerBlock.Add(vInt2);
            code.Add(innerBlock);

            var r = TranslateGeneratedCode(target, code);

            Assert.IsTrue(r.ContainsKey("NumberOfQueryFunctions"), "Number of functions isn't here");
            Assert.IsInstanceOfType(r["NumberOfQueryFunctions"], typeof(int), "# function type");
            Assert.AreEqual(1, r["NumberOfQueryFunctions"], "# of functions");

            Assert.IsTrue(r.ContainsKey("QueryFunctionBlocks"), "Missing query function blocks");
            Assert.IsInstanceOfType(r["QueryFunctionBlocks"], typeof(IEnumerable<IEnumerable<string>>), "Type is incorrect");
            var codeBlocks = r["QueryFunctionBlocks"] as IEnumerable<IEnumerable<string>>;
            Assert.AreEqual(1, codeBlocks.Count(), "Wrong number of code blocks");
        }
Пример #6
0
 public void AddQMFunc()
 {
     var gc = new GeneratedCode();
     Assert.AreEqual(0, gc.QMFunctions.Count(), "# of functions before add");
     gc.Add(new QMFuncSource());
     Assert.AreEqual(1, gc.QMFunctions.Count(), "# of functions before add");
 }
Пример #7
0
        public void CombineOneTwoLevelAndOneOneLevelFunctions2()
        {
            var q1 = new GeneratedCode();
            var q2 = new GeneratedCode();

            var f1 = QMFuncUtils.GenerateFunction();
            var r1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var s1 = new Statements.StatementAssign(r1, new Variables.ValSimple(f1.Name + "()", typeof(int)));
            var f2 = GenerateFunction2();
            var r2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var s2 = new Statements.StatementAssign(r2, new Variables.ValSimple(f2[1].Name + "()", typeof(int)));

            q1.Add(f1);
            q1.Add(s1);
            q1.SetResult(r1);

            q2.Add(f2[0]);
            q2.Add(f2[1]);
            q2.Add(s2);
            q2.SetResult(r2);

            var target = new CombinedGeneratedCode();

            target.AddGeneratedCode(q1);
            target.AddGeneratedCode(q2);

            target.DumpCodeToConsole();

            Assert.AreEqual(2, target.Functions.Count(), "# of functions should be combined to 2");
            Assert.AreEqual(1, target.QueryCode().Count(), "# of query code blocks");
            Assert.AreEqual(2, target.QueryCode().First().Statements.Count(), "# of statements in the combined block.");
            Assert.IsFalse(target.DumpCode().Where(l => l.Contains(f2[0].Name)).Any(), "The new function was still in there");
        }
Пример #8
0
        public void TestPopUpOneLevelLoopInline()
        {
            GeneratedCode gc = new GeneratedCode();

            gc.Add(new StatementInlineBlock());
            gc.Pop(true);
        }
Пример #9
0
        public void TestFirstBookingBad()
        {
            var i  = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var gc = new GeneratedCode();

            Assert.IsNull(gc.FirstAllInScopeFromNow(new IDeclaredParameter[] { i }));
        }
Пример #10
0
        public void TestAddOutsideLoopWithJustInlineBLock()
        {
            var target = new GeneratedCode();

            target.Add(new Statements.StatementInlineBlock());
            target.AddOutsideLoop(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
        }
Пример #11
0
        public void AddQMFunc()
        {
            var gc = new GeneratedCode();

            Assert.AreEqual(0, gc.QMFunctions.Count(), "# of functions before add");
            gc.Add(new QMFuncSource());
            Assert.AreEqual(1, gc.QMFunctions.Count(), "# of functions before add");
        }
Пример #12
0
        public void TestResultScopeNull()
        {
            var gc = new GeneratedCode();
            var b  = new StatementInlineBlock();

            gc.Add(b);
            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
        }
Пример #13
0
        public void TestInScopeDownOneOK()
        {
            var gc = new GeneratedCode();
            var sc = gc.CurrentScope;

            gc.Add(new StatementFilter(new ValSimple("true", typeof(bool))));
            Assert.IsTrue(gc.InScopeNow(sc), "current scope should be in scope now.");
        }
Пример #14
0
        public void TestAddOneLevelUpSingleLevel()
        {
            GeneratedCode gc = new GeneratedCode();

            gc.Add(new Statements.StatementInlineBlock());
            gc.AddOneLevelUp(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
            Assert.AreEqual(1, gc.CodeBody.DeclaredVariables.Count(), "Expected top level declaration");
        }
Пример #15
0
        public void RemoveMissingStatement()
        {
            var fixture = new GeneratedCode();

            fixture.Add(new StatementInlineBlock());
            var s1 = new SimpleStatement();

            fixture.Remove(s1);
        }
Пример #16
0
        public void TestFirstBookingThisLevel()
        {
            var i  = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var gc = new GeneratedCode();

            gc.Add(i);
            var r = gc.FirstAllInScopeFromNow(new IDeclaredParameter[] { i });

            Assert.AreEqual(r, gc.CodeBody, "Same code body.");
        }
Пример #17
0
        public void TestRememberExprSimpleByVal()
        {
            var gc   = new GeneratedCode();
            var expr = Expression.Constant(10);
            var r    = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));

            gc.RememberSubexpression(expr, r);

            Assert.AreEqual(r, gc.LookupSubexpression(Expression.Constant(10)), "Could not find expression");
        }
Пример #18
0
        public void TestRememberConstantObject()
        {
            var gc   = new GeneratedCode();
            var expr = Expression.Constant(new ROOTNET.NTH1F());
            var r1   = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));

            gc.RememberSubexpression(expr, r1);

            Assert.AreEqual(r1, gc.LookupSubexpression(expr), "Constant Expressions of arbitrary objects can't be looked up");
        }
Пример #19
0
        public void TestNameCombo()
        {
            GeneratedCode gc  = new GeneratedCode();
            var           obj = new ROOTNET.NTH1F("hi", "there", 10, 0.0, 10.0);
            var           n1  = gc.QueueForTransfer(obj);
            var           n2  = gc.QueueForTransfer(obj);

            Assert.AreEqual(n1, n2, "Names should be identical");
            Assert.AreEqual(1, gc.VariablesToTransfer.Count(), "# of variables to move over wire");
        }
Пример #20
0
        public void TestAddOutsideLoopWithOnStatement()
        {
            var target = new GeneratedCode();
            var blk    = new Statements.StatementInlineBlock();

            target.Add(blk);
            target.Add(new LINQToTTreeLib.Tests.TestUtils.SimpleLoop());
            target.AddOutsideLoop(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
            Assert.AreEqual(1, blk.DeclaredVariables.Count(), "# of loop declared variables");
        }
Пример #21
0
        public void TestFirstBookingNextLevel()
        {
            var i  = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var gc = new GeneratedCode();

            gc.Add(i);
            gc.Add(new StatementFilter(new ValSimple("dude", typeof(bool))));
            var r = gc.FirstAllInScopeFromNow(new IDeclaredParameter[] { i });

            Assert.AreEqual(r, gc.CodeBody, "Same code body.");
        }
Пример #22
0
        public void TestPopUpOneLevelLoopWithLoop()
        {
            GeneratedCode gc    = new GeneratedCode();
            var           loopV = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));

            gc.Add(new StatementForLoop(loopV, new Variables.ValSimple("5", typeof(int))));
            gc.Pop(true);
            Assert.AreEqual(1, gc.CodeBody.Statements.Count(), "# of statements present now");
            gc.Add(new StatementAssign(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)), new Variables.ValSimple("ih", typeof(int))));
            Assert.AreEqual(2, gc.CodeBody.Statements.Count(), "# of statements present now");
        }
Пример #23
0
        public void CheckDepthAndPopWorkTogether()
        {
            var target = new GeneratedCode();
            var s1     = new StatementInlineBlock();

            target.Add(s1);
            var s2 = new StatementInlineBlock();

            target.Add(s2);
            Assert.AreEqual(3, target.Depth);
            target.Pop();
            Assert.AreEqual(2, target.Depth);
        }
Пример #24
0
        public void TestTranslateForIncludeFiles()
        {
            CPPTranslator target = new CPPTranslator();
            var           obj    = DeclarableParameter.CreateDeclarableParameterExpression(typeof(ROOTNET.NTH1F));
            GeneratedCode code   = new GeneratedCode();

            code.SetResult(obj);

            var r = TranslateGeneratedCode(target, code);

            Assert.AreEqual(1, code.IncludeFiles.Count(), "# of include files");
            Assert.AreEqual("TH1F.h", code.IncludeFiles.First(), "include file name is incorrect");
        }
        internal void CheckAddIncludeFiles([PexAssumeNotNull] string[] incnames)
        {
            var cc = new CombinedGeneratedCode();
            foreach (var item in incnames)
            {
                var gc = new GeneratedCode();
                gc.AddIncludeFile(item);
                cc.AddGeneratedCode(gc);
            }

            HashSet<string> unique = new HashSet<string>(incnames);
            Assert.AreEqual(unique.Count, cc.IncludeFiles.Count(), "wrong # of unqiue names");
        }
Пример #26
0
        public void RemoveStatement()
        {
            var fixture = new GeneratedCode();

            fixture.Add(new StatementInlineBlock());
            var s1 = new SimpleStatement();

            fixture.Add(s1);

            Assert.AreEqual(1, (fixture.CodeBody.Statements.First() as IBookingStatementBlock).Statements.Count(), "before removal");
            fixture.Remove(s1);
            Assert.AreEqual(0, (fixture.CodeBody.Statements.First() as IBookingStatementBlock).Statements.Count(), "after removal");
        }
Пример #27
0
        public void TestRememberTwoSameConstantObjects()
        {
            var gc    = new GeneratedCode();
            var expr1 = Expression.Constant(new ROOTNET.NTH1F());
            var expr2 = Expression.Constant(new ROOTNET.NTH1F());
            var r1    = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));
            var r2    = new LINQToTTreeLib.Variables.ValSimple("11", typeof(int));

            gc.RememberSubexpression(expr1, r1);
            gc.RememberSubexpression(expr2, r2);

            Assert.AreEqual(r1, gc.LookupSubexpression(expr1), "expr1 failure");
            Assert.AreEqual(r2, gc.LookupSubexpression(expr2), "expr2 failure");
        }
        internal void CheckAddSameVariableNamesToTransfer([PexAssumeNotNull] ROOTNET.NTObject[] varnames)
        {
            var cc = new CombinedGeneratedCode();
            HashSet<string> unique = new HashSet<string>();
            foreach (var item in varnames)
            {
                var gc = new GeneratedCode();
                var name = gc.QueueForTransfer(item);
                unique.Add(name);
                cc.AddGeneratedCode(gc);
            }

            Assert.AreEqual(unique.Count, varnames.Length, "there are non-unique names and there are no errors!");
            Assert.AreEqual(varnames.Length, cc.VariablesToTransfer.Count(), "bad number added");
        }
Пример #29
0
        public void TestCompoundPostInsert()
        {
            var gc = new GeneratedCode();

            gc.Add(new Statements.StatementSimpleStatement("dir"));
            var block = new Statements.StatementInlineBlock();

            gc.Add(block);
            gc.Add(new Statements.StatementSimpleStatement("dir"));
            gc.Add(new Statements.StatementSimpleStatement("fork"));
            gc.Pop();
            gc.Add(new Statements.StatementSimpleStatement("dir"));

            Assert.AreEqual(3, gc.CodeBody.Statements.Count(), "# of statements");
        }
Пример #30
0
        public void TestRememberExprPop()
        {
            var gc           = new GeneratedCode();
            var initialScope = gc.CurrentScope;

            gc.Add(new StatementInlineBlock());

            var expr = Expression.Constant(10);
            var r    = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));

            gc.RememberSubexpression(expr, r);

            gc.CurrentScope = initialScope;

            Assert.IsNull(gc.LookupSubexpression(Expression.Constant(10)), "Expression after popping");
        }
Пример #31
0
 internal Expression ProcessResultOperator(
     [PexAssumeUnderTest]ROCount target,
     CountResultOperator resultOperator,
     QueryModel queryModel,
     GeneratedCode codeEnv
 )
 {
     int origCount = 0;
     if (codeEnv != null)
         origCount = codeEnv.CodeBody.Statements.Count();
     CodeContext c = new CodeContext();
     Expression result = target.ProcessResultOperator(resultOperator, queryModel, codeEnv, c, null);
     Assert.AreEqual(origCount + 1, codeEnv.CodeBody.Statements.Count(), "Expected an added statement!");
     Assert.IsInstanceOfType(codeEnv.CodeBody.Statements.Last(), typeof(StatementAggregate), "Statement to inc the integer must have been done!");
     Assert.AreEqual(result.Type, typeof(int), "Expected to be calculating an integer");
     return result;
 }
Пример #32
0
        public void TestTranslateWithInitialValue()
        {
            CPPTranslator target = new CPPTranslator();
            var vInt = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            vInt.SetInitialValue("2");
            GeneratedCode code = new GeneratedCode();
            code.SetResult(vInt);

            var r = TranslateGeneratedCode(target, code);

            Assert.IsTrue(r.ContainsKey("ResultVariables"), "Result variable is missing");
            Assert.IsInstanceOfType(r["ResultVariables"], typeof(IEnumerable<CPPTranslator.VarInfo>), "bad type for the result variable");
            var rList = r["ResultVariables"] as IEnumerable<CPPTranslator.VarInfo>;
            Assert.AreEqual(1, rList.Count(), "incorrect # of result variables");
            var rv = rList.First();
            Assert.AreEqual("2", rv.InitialValue, "initial value");
        }
Пример #33
0
        public void Pop(IStatement s, bool popPastLoop)
        {
            var gc = new GeneratedCode();
            int depth = gc.Depth;
            gc.Add(s);

            bool good = s is IBookingStatementBlock;
            try
            {
                gc.Pop(popPastLoop);
                Assert.AreEqual(depth, gc.Depth, "Depth isn't set correctly");
                Assert.IsTrue(good, "booking statement");
            }
            catch (InvalidOperationException)
            {
                Assert.IsFalse(good, "a booking statement");
            }
        }
Пример #34
0
        public void TestRememberEmbededConstExpr()
        {
            var gc = new GeneratedCode();
            var c1 = Expression.Constant(new ROOTNET.NTH1F("hi", "there", 100, 0.0, 10.0));
            var c2 = Expression.Constant(new ROOTNET.NTH1F("no", "way", 100, 0.0, 10.0));

            var n1 = Expression.Call(c1, typeof(ROOTNET.NTH1F).GetMethod("GetNbinsX"));
            var n2 = Expression.Call(c2, typeof(ROOTNET.NTH1F).GetMethod("GetNbinsX"));

            var r1 = new ValSimple("1", typeof(int));
            var r2 = new ValSimple("2", typeof(int));

            gc.RememberSubexpression(n1, r1);
            gc.RememberSubexpression(n2, r2);

            Assert.AreEqual(r1, gc.LookupSubexpression(n1), "lookup n1");
            Assert.AreEqual(r2, gc.LookupSubexpression(n2), "lookup n2");
        }
Пример #35
0
        public void TestResultScopePop()
        {
            var gc = new GeneratedCode();
            var b1 = new StatementInlineBlock();

            gc.Add(b1);

            var b2 = new StatementInlineBlock();

            gc.Add(b2);
            gc.SetCurrentScopeAsResultScope();

            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));

            // This pop should remove the result scope, and it should be back to "null" now, which
            // should cause an exception.

            gc.Pop();
            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
        }
Пример #36
0
        public void Pop(IStatement s, bool popPastLoop)
        {
            var gc    = new GeneratedCode();
            int depth = gc.Depth;

            gc.Add(s);

            bool good = s is IBookingStatementBlock;

            try
            {
                gc.Pop(popPastLoop);
                Assert.AreEqual(depth, gc.Depth, "Depth isn't set correctly");
                Assert.IsTrue(good, "booking statement");
            }
            catch (InvalidOperationException)
            {
                Assert.IsFalse(good, "a booking statement");
            }
        }
Пример #37
0
        public void TestRememberExprHideAndSeek()
        {
            var gc   = new GeneratedCode();
            var expr = Expression.Constant(5);
            var r1   = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));

            gc.RememberSubexpression(expr, r1);

            var initialScope = gc.CurrentScope;

            gc.Add(new StatementInlineBlock());

            var r2 = new LINQToTTreeLib.Variables.ValSimple("11", typeof(int));

            gc.RememberSubexpression(expr, r2);

            Assert.AreEqual(r2, gc.LookupSubexpression(expr), "Is hidden one done right?");
            gc.Pop();
            Assert.AreEqual(r1, gc.LookupSubexpression(expr), "Is revealed one done right?");
        }
Пример #38
0
 public void TestResultScopeNull()
 {
     var gc = new GeneratedCode();
     var b = new StatementInlineBlock();
     gc.Add(b);
     gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
 }
Пример #39
0
        public void TestResultScopeCurrentScope()
        {
            var gc = new GeneratedCode();
            var b1 = new StatementInlineBlock();
            gc.Add(b1);
            gc.SetCurrentScopeAsResultScope();
            var outterScope = gc.CurrentScope;

            var b2 = new StatementInlineBlock();
            gc.Add(b2);
            gc.SetCurrentScopeAsResultScope();

            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));

            Assert.AreEqual(0, b1.DeclaredVariables.Count(), "variables at outside loop after 0 add");
            Assert.AreEqual(1, b2.DeclaredVariables.Count(), "variables at inner loop after 1 add");

            gc.CurrentScope = outterScope;

            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));

            Assert.AreEqual(1, b1.DeclaredVariables.Count(), "variables at outside loop after 1 add");
            Assert.AreEqual(1, b2.DeclaredVariables.Count(), "variables at inner loop after 2 add");
        }
Пример #40
0
 public void TestAddOutsideLoopWithJustIn2Loops()
 {
     var target = new GeneratedCode();
     target.Add(new Statements.StatementInlineBlock());
     var loop = new LINQToTTreeLib.Tests.TestUtils.SimpleLoop();
     target.Add(loop);
     target.Add(new LINQToTTreeLib.Tests.TestUtils.SimpleLoop());
     target.AddOutsideLoop(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
     Assert.AreEqual(1, loop.DeclaredVariables.Count(), "# of loop declared variables");
 }
Пример #41
0
 public void TestFirstBookingNextLevelIt()
 {
     var i = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
     var gc = new GeneratedCode();
     var ifs = new StatementFilter(new ValSimple("dude", typeof(bool)));
     gc.Add(ifs);
     gc.Add(i);
     var r = gc.FirstAllInScopeFromNow(new IDeclaredParameter[] { i });
     Assert.AreEqual(r, ifs, "Same code body.");
 }
Пример #42
0
 public void TestPopUpOneLevelLoopWithLoopDeeper()
 {
     GeneratedCode gc = new GeneratedCode();
     var loopV = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
     gc.Add(new StatementForLoop(loopV, new Variables.ValSimple("5", typeof(int))));
     gc.Add(new StatementInlineBlock());
     gc.Add(new StatementAssign(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)), new Variables.ValSimple("ih", typeof(int))));
     gc.Pop(true);
     Assert.AreEqual(1, gc.CodeBody.Statements.Count(), "# of statements present now");
     gc.Add(new StatementAssign(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)), new Variables.ValSimple("ih", typeof(int))));
     Assert.AreEqual(2, gc.CodeBody.Statements.Count(), "# of statements present now");
 }
Пример #43
0
 public void TestFirstBookingBad()
 {
     var i = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
     var gc = new GeneratedCode();
     Assert.IsNull(gc.FirstAllInScopeFromNow(new IDeclaredParameter[] { i }));
 }
Пример #44
0
        public void TestRememberEmbededConstExpr()
        {
            var gc = new GeneratedCode();
            var c1 = Expression.Constant(new ROOTNET.NTH1F("hi", "there", 100, 0.0, 10.0));
            var c2 = Expression.Constant(new ROOTNET.NTH1F("no", "way", 100, 0.0, 10.0));

            var n1 = Expression.Call(c1, typeof(ROOTNET.NTH1F).GetMethod("GetNbinsX"));
            var n2 = Expression.Call(c2, typeof(ROOTNET.NTH1F).GetMethod("GetNbinsX"));

            var r1 = new ValSimple("1", typeof(int));
            var r2 = new ValSimple("2", typeof(int));

            gc.RememberSubExpression(n1, r1);
            gc.RememberSubExpression(n2, r2);

            Assert.AreEqual(r1, gc.LookupSubExpression(n1), "lookup n1");
            Assert.AreEqual(r2, gc.LookupSubExpression(n2), "lookup n2");
        }
Пример #45
0
        public void TestRememberConstantObject()
        {
            var gc = new GeneratedCode();
            var expr = Expression.Constant(new ROOTNET.NTH1F());
            var r1 = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));
            gc.RememberSubExpression(expr, r1);

            Assert.AreEqual(r1, gc.LookupSubExpression(expr), "Constant Expressions of arbitrary objects can't be looked up");
        }
Пример #46
0
        public void TestRememberTwoSameConstantObjects()
        {
            var gc = new GeneratedCode();
            var expr1 = Expression.Constant(new ROOTNET.NTH1F());
            var expr2 = Expression.Constant(new ROOTNET.NTH1F());
            var r1 = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));
            var r2 = new LINQToTTreeLib.Variables.ValSimple("11", typeof(int));
            gc.RememberSubExpression(expr1, r1);
            gc.RememberSubExpression(expr2, r2);

            Assert.AreEqual(r1, gc.LookupSubExpression(expr1), "expr1 failure");
            Assert.AreEqual(r2, gc.LookupSubExpression(expr2), "expr2 failure");
        }
Пример #47
0
 public void TestInScopeNoChangeInScope()
 {
     var gc = new GeneratedCode();
     Assert.IsTrue(gc.InScopeNow(gc.CurrentScope), "current scope should be in scope now.");
 }
Пример #48
0
 public void TestInScopeUpOneNotOK()
 {
     var gc = new GeneratedCode();
     gc.Add(new StatementFilter(new ValSimple("true", typeof(bool))));
     var sc = gc.CurrentScope;
     gc.Pop();
     Assert.IsFalse(gc.InScopeNow(sc), "current scope should be in scope now.");
 }
Пример #49
0
        public void TestCompoundPostInsert()
        {
            var gc = new GeneratedCode();
            gc.Add(new Statements.StatementSimpleStatement("dir"));
            var block = new Statements.StatementInlineBlock();
            gc.Add(block);
            gc.Add(new Statements.StatementSimpleStatement("dir"));
            gc.Add(new Statements.StatementSimpleStatement("fork"));
            gc.Pop();
            gc.Add(new Statements.StatementSimpleStatement("dir"));

            Assert.AreEqual(3, gc.CodeBody.Statements.Count(), "# of statements");
        }
Пример #50
0
 public void TestPopUpOneLevelLoopEmpty()
 {
     GeneratedCode gc = new GeneratedCode();
     gc.Pop(true);
 }
Пример #51
0
        public void TestRememberExprHideAndSeek()
        {
            var gc = new GeneratedCode();
            var expr = Expression.Constant(5);
            var r1 = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));
            gc.RememberSubExpression(expr, r1);

            var initialScope = gc.CurrentScope;
            gc.Add(new StatementInlineBlock());

            var r2 = new LINQToTTreeLib.Variables.ValSimple("11", typeof(int));
            gc.RememberSubExpression(expr, r2);

            Assert.AreEqual(r2, gc.LookupSubExpression(expr), "Is hidden one done right?");
            gc.Pop();
            Assert.AreEqual(r1, gc.LookupSubExpression(expr), "Is revealed one done right?");
        }
Пример #52
0
 public void TestFirstBookingThisLevel()
 {
     var i = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
     var gc = new GeneratedCode();
     gc.Add(i);
     var r = gc.FirstAllInScopeFromNow(new IDeclaredParameter[] { i });
     Assert.AreEqual(r, gc.CodeBody, "Same code body.");
 }
Пример #53
0
 public void TestPopUpOneLevelLoopInline()
 {
     GeneratedCode gc = new GeneratedCode();
     gc.Add(new StatementInlineBlock());
     gc.Pop(true);
 }
Пример #54
0
        public void TestRememberExprPop()
        {
            var gc = new GeneratedCode();
            var initialScope = gc.CurrentScope;
            gc.Add(new StatementInlineBlock());

            var expr = Expression.Constant(10);
            var r = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));
            gc.RememberSubExpression(expr, r);

            gc.CurrentScope = initialScope;

            Assert.IsNull(gc.LookupSubExpression(Expression.Constant(10)), "Expression after popping");
        }
Пример #55
0
 public void TestPopUpOneLevel()
 {
     GeneratedCode gc = new GeneratedCode();
     gc.Pop();
 }
Пример #56
0
        public void TestRememberExprSimpleByVal()
        {
            var gc = new GeneratedCode();
            var expr = Expression.Constant(10);
            var r = new LINQToTTreeLib.Variables.ValSimple("10", typeof(int));

            gc.RememberSubExpression(expr, r);

            Assert.AreEqual(r, gc.LookupSubExpression(Expression.Constant(10)), "Could not find expression");
        }
Пример #57
0
 public void TestAddOutsideLoopWithJustInlineBLock()
 {
     var target = new GeneratedCode();
     target.Add(new Statements.StatementInlineBlock());
     target.AddOutsideLoop(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));
 }
Пример #58
0
        public void TestResultScopePop()
        {
            var gc = new GeneratedCode();
            var b1 = new StatementInlineBlock();
            gc.Add(b1);

            var b2 = new StatementInlineBlock();
            gc.Add(b2);
            gc.SetCurrentScopeAsResultScope();

            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));

            // This pop should remove the result scope, and it should be back to "null" now, which
            // should cause an exception.

            gc.Pop();
            gc.AddAtResultScope(DeclarableParameter.CreateDeclarableParameterExpression(typeof(int)));

        }
Пример #59
0
        public void RemoveStatement()
        {
            var fixture = new GeneratedCode();
            fixture.Add(new StatementInlineBlock());
            var s1 = new SimpleStatement();
            fixture.Add(s1);

            Assert.AreEqual(1, (fixture.CodeBody.Statements.First() as IBookingStatementBlock).Statements.Count(), "before removal");
            fixture.Remove(s1);
            Assert.AreEqual(0, (fixture.CodeBody.Statements.First() as IBookingStatementBlock).Statements.Count(), "after removal");
        }
Пример #60
0
 public void RemoveMissingStatement()
 {
     var fixture = new GeneratedCode();
     fixture.Add(new StatementInlineBlock());
     var s1 = new SimpleStatement();
     fixture.Remove(s1);
 }