Exemple #1
0
        public void TestCombineWithSameArray()
        {
            var index1      = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var index2      = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var arrayRecord = DeclarableParameter.CreateDeclarableParameterArrayExpression(typeof(int));
            var stp1        = new StatementPairLoop(arrayRecord, index1, index2);

            var index3  = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var index4  = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var stp2    = new StatementPairLoop(arrayRecord, index3, index4);
            var statAss = new StatementAssign(index3, new ValSimple("dude", typeof(int)), null);

            stp2.Add(statAss);

            var opt = new Factories.CodeOptimizerTest(true);

            Assert.IsTrue(stp1.TryCombineStatement(stp2, opt), "Combine should have been ok");
            Assert.AreEqual(1, stp1.Statements.Count(), "Improper number of combined sub-statements");
            var s1 = stp1.Statements.First();

            Assert.IsInstanceOfType(s1, typeof(StatementAssign), "Statement is not right type");
            var sa = s1 as StatementAssign;

            Assert.AreEqual(index1.RawValue, sa.ResultVariable.RawValue, "rename of variables didn't occur correctly");
        }
        public void TestCombineWithSameArray()
        {

            var index1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var index2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var arrayRecord = DeclarableParameter.CreateDeclarableParameterArrayExpression(typeof(int));
            var stp1 = new StatementPairLoop(arrayRecord, index1, index2);

            var index3 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var index4 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var stp2 = new StatementPairLoop(arrayRecord, index3, index4);
            var statAss = new StatementAssign(index3, new ValSimple("dude", typeof(int)), null);
            stp2.Add(statAss);

            var opt = new Factories.CodeOptimizerTest(true);
            Assert.IsTrue(stp1.TryCombineStatement(stp2, opt), "Combine should have been ok");
            Assert.AreEqual(1, stp1.Statements.Count(), "Improper number of combined sub-statements");
            var s1 = stp1.Statements.First();
            Assert.IsInstanceOfType(s1, typeof(StatementAssign), "Statement is not right type");
            var sa = s1 as StatementAssign;
            Assert.AreEqual(index1.RawValue, sa.ResultVariable.RawValue, "rename of variables didn't occur correctly");
        }