Exemplo n.º 1
0
        public BooleanExpression(Method method, Primitives primitive)
        {
            if (primitive == null)
            {
                return;
            }

            if (!ProgGenUtil.getPrimitivesOfVariables(method).contains(primitive))
            {
                return;
            }

            Random rand   = new Random();
            int    option = rand.Next(100);

            if (option < method.AssociatedClass.Percent)
            {
                leftExpr  = new BooleanExpression(method, primitive);
                op        = new ConjunctOperator();
                rightExpr = new BooleanExpression(method, primitive);
            }
            else
            {
                leftExpr  = new NormalExpression(method, primitive);
                op        = new BooleanOperator(primitive);
                rightExpr = new NormalExpression(method, primitive);

                //we also don't want if(i8 != i8)
                while (leftExpr.ToString().Equals(rightExpr.ToString()))
                {
                    rightExpr = new NormalExpression(method, primitive);
                }
            }
        }
Exemplo n.º 2
0
        public IfStmtIfStmt(Method method, List <ClassGenerator> classList)
        {
            this.method = method;

            HashSet <Primitives> primitiveSet = ProgGenUtil.getPrimitivesOfVariables(method);

            cond = new BooleanExpression(method, ProgGenUtil.getRandomizedPrimitiveForBooleanExpression(primitiveSet));

            //adding two extra lines for each nested loop
            method.Loc = method.Loc + 2;

            Random rand   = new Random();
            int    option = rand.Next(100);

            //We want more nested if's but not more than the MAX.
            if ((option < method.AssociatedClass.Percent + 40) && (method.NestedIfCounter < method.MaxNestedIfs))
            {
                // counts the nested ifs
                method.NestedIfCounter = method.NestedIfCounter + 1;
                //Start.nestedIf_counter++;
                body += (new IfStmtIfStmt(method, classList)).ToString();
            }
            else
            {
                body = Statement.getRandomizedStatement(method, classList).ToString();
            }
        }
Exemplo n.º 3
0
        public IfElse(Method method, List <ClassGenerator> classList)
        {
            this.method = method;
            method.Loc  = method.Loc + 4;
            // 'if' and 'else' themselves contribute 4 lines in the loc
            HashSet <Primitives> primitiveSet = ProgGenUtil.getPrimitivesOfVariables(method);

            boolExpr = new BooleanExpression(method, ProgGenUtil.getRandomizedPrimitiveForBooleanExpression(primitiveSet));
            thenStmt = Statement.getRandomizedStatement(method, classList);
            elseStmt = Statement.getRandomizedStatement(method, classList);
        }