Ejemplo n.º 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");
        }
Ejemplo n.º 2
0
        public void TestCombineShouldFail()
        {
            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 arrayRecord2 = DeclarableParameter.CreateDeclarableParameterArrayExpression(typeof(int));
            var stp2         = new StatementPairLoop(arrayRecord2, index3, index4);

            Assert.IsFalse(stp1.TryCombineStatement(stp2, null), "should not have combined");
        }
Ejemplo n.º 3
0
        public bool TestTryCombine([PexAssumeUnderTest] StatementPairLoop pairloop, IStatement statement, ICodeOptimizationService codeOpt)
        {
            var result = pairloop.TryCombineStatement(statement, codeOpt);

            return(result);
        }