Search in sources :

Example 6 with Comparator

use of org.evosuite.symbolic.expr.Comparator in project evosuite by EvoSuite.

the class ConstraintToZ3Visitor method visit.

@Override
public SmtExpr visit(StringConstraint c, Void arg) {
    ExprToZ3Visitor v = new ExprToZ3Visitor();
    StringComparison stringComparison = (StringComparison) c.getLeftOperand();
    IntegerConstant integerConstant = (IntegerConstant) c.getRightOperand();
    SmtExpr left = stringComparison.accept(v, null);
    SmtExpr right = integerConstant.accept(v, null);
    if (left == null || right == null) {
        return null;
    }
    Comparator cmp = c.getComparator();
    return mkComparison(left, cmp, right);
}
Also used : StringComparison(org.evosuite.symbolic.expr.bv.StringComparison) SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Comparator(org.evosuite.symbolic.expr.Comparator)

Example 7 with Comparator

use of org.evosuite.symbolic.expr.Comparator in project evosuite by EvoSuite.

the class ConstraintToZ3Visitor method visit.

@Override
public SmtExpr visit(RealConstraint c, Void arg) {
    ExprToZ3Visitor v = new ExprToZ3Visitor();
    SmtExpr left = c.getLeftOperand().accept(v, null);
    SmtExpr right = c.getRightOperand().accept(v, null);
    if (left == null || right == null) {
        return null;
    }
    Comparator cmp = c.getComparator();
    SmtExpr boolExpr = mkComparison(left, cmp, right);
    return boolExpr;
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) Comparator(org.evosuite.symbolic.expr.Comparator)

Example 8 with Comparator

use of org.evosuite.symbolic.expr.Comparator in project evosuite by EvoSuite.

the class DeprecatedTestSuiteDSE method calculateUncoveredBranches.

/**
 * Iterate over path constraints to identify those which map to branches
 * that are only covered one way
 */
private void calculateUncoveredBranches() {
    unsolvedBranchConditions.clear();
    if (Properties.DSE_NEGATE_ALL_CONDITIONS == true) {
        for (TestChromosome testChromosome : pathConditions.keySet()) {
            final List<BranchCondition> pathCondition = pathConditions.get(testChromosome);
            for (BranchCondition branch : pathCondition) {
                if (!unsolvableBranchConditions.contains(branch)) {
                    unsolvedBranchConditions.add(new TestBranchPair(testChromosome, pathCondition, branch));
                }
            }
        }
    } else {
        Map<String, Map<Comparator, Set<TestBranchPair>>> solvedConstraints = new HashMap<String, Map<Comparator, Set<TestBranchPair>>>();
        for (TestChromosome test : pathConditions.keySet()) {
            final List<BranchCondition> pathCondition = pathConditions.get(test);
            for (BranchCondition branch : pathCondition) {
                if (unsolvableBranchConditions.contains(branch))
                    continue;
                String index = getBranchIndex(branch);
                if (!solvedConstraints.containsKey(index))
                    solvedConstraints.put(index, new HashMap<Comparator, Set<TestBranchPair>>());
                Constraint<?> c = branch.getConstraint();
                if (!solvedConstraints.get(index).containsKey(c.getComparator()))
                    solvedConstraints.get(index).put(c.getComparator(), new HashSet<TestBranchPair>());
                solvedConstraints.get(index).get(c.getComparator()).add(new TestBranchPair(test, pathCondition, branch));
            }
        }
        for (String index : solvedConstraints.keySet()) {
            if (solvedConstraints.get(index).size() == 1) {
                Set<TestBranchPair> branches = solvedConstraints.get(index).values().iterator().next();
                unsolvedBranchConditions.addAll(branches);
            }
        }
        logger.info("Update set of unsolved branch conditions to " + unsolvedBranchConditions.size());
        if (Properties.DSE_RANK_BRANCH_CONDITIONS == false) {
            Randomness.shuffle((ArrayList<TestBranchPair>) unsolvedBranchConditions);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) BranchCondition(org.evosuite.symbolic.BranchCondition) Comparator(org.evosuite.symbolic.expr.Comparator) TestChromosome(org.evosuite.testcase.TestChromosome) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with Comparator

use of org.evosuite.symbolic.expr.Comparator in project evosuite by EvoSuite.

the class ConstraintToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(IntegerConstraint c, Void arg) {
    ExprToZ3Str2Visitor v = new ExprToZ3Str2Visitor();
    SmtExpr left = c.getLeftOperand().accept(v, null);
    SmtExpr right = c.getRightOperand().accept(v, null);
    if (left == null || right == null) {
        return null;
    }
    Comparator cmp = c.getComparator();
    return mkComparison(left, cmp, right);
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) Comparator(org.evosuite.symbolic.expr.Comparator)

Example 10 with Comparator

use of org.evosuite.symbolic.expr.Comparator in project evosuite by EvoSuite.

the class ConstraintToZ3Str2Visitor method visit.

@Override
public SmtExpr visit(StringConstraint c, Void arg) {
    ExprToZ3Str2Visitor v = new ExprToZ3Str2Visitor();
    SmtExpr left = c.getLeftOperand().accept(v, null);
    SmtExpr right = c.getRightOperand().accept(v, null);
    if (left == null || right == null) {
        return null;
    }
    Comparator cmp = c.getComparator();
    return mkComparison(left, cmp, right);
}
Also used : SmtExpr(org.evosuite.symbolic.solver.smt.SmtExpr) Comparator(org.evosuite.symbolic.expr.Comparator)

Aggregations

Comparator (org.evosuite.symbolic.expr.Comparator)12 SmtExpr (org.evosuite.symbolic.solver.smt.SmtExpr)6 Constraint (org.evosuite.symbolic.expr.Constraint)2 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)2 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)2 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 BranchCondition (org.evosuite.symbolic.BranchCondition)1 IntegerComparison (org.evosuite.symbolic.expr.bv.IntegerComparison)1 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)1 RealComparison (org.evosuite.symbolic.expr.bv.RealComparison)1 StringComparison (org.evosuite.symbolic.expr.bv.StringComparison)1 TestChromosome (org.evosuite.testcase.TestChromosome)1