All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.evosuite.coverage.mutation.MutationFactory Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
 * contributors
 *
 * This file is part of EvoSuite.
 *
 * EvoSuite is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3.0 of the License, or
 * (at your option) any later version.
 *
 * EvoSuite is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with EvoSuite. If not, see .
 */
/**
 * 
 */
package org.evosuite.coverage.mutation;

import java.util.ArrayList;
import java.util.List;

import org.evosuite.Properties;
import org.evosuite.instrumentation.mutation.InsertUnaryOperator;
import org.evosuite.instrumentation.mutation.ReplaceArithmeticOperator;
import org.evosuite.instrumentation.mutation.ReplaceConstant;
import org.evosuite.instrumentation.mutation.ReplaceVariable;
import org.evosuite.rmi.ClientServices;
import org.evosuite.statistics.RuntimeVariable;
import org.evosuite.testsuite.AbstractFitnessFactory;

/**
 * 

* MutationFactory class. *

* * @author fraser */ public class MutationFactory extends AbstractFitnessFactory { private boolean strong = true; protected List goals = null; /** *

* Constructor for MutationFactory. *

*/ public MutationFactory() { } /** *

* Constructor for MutationFactory. *

* * @param strongMutation * a boolean. */ public MutationFactory(boolean strongMutation) { this.strong = strongMutation; } /* (non-Javadoc) * @see org.evosuite.coverage.TestFitnessFactory#getCoverageGoals() */ /** {@inheritDoc} */ @Override public List getCoverageGoals() { return getCoverageGoals(null); } /** *

* getCoverageGoals *

* * @param targetMethod * a {@link java.lang.String} object. * @return a {@link java.util.List} object. */ public List getCoverageGoals(String targetMethod) { if (goals != null) return goals; goals = new ArrayList(); for (Mutation m : getMutantsLimitedPerClass()) { if (targetMethod != null && !m.getMethodName().endsWith(targetMethod)) continue; // We need to return all mutants to make coverage values and bitstrings consistent //if (MutationTimeoutStoppingCondition.isDisabled(m)) // continue; if (strong) goals.add(new StrongMutationTestFitness(m)); else goals.add(new WeakMutationTestFitness(m)); } ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Mutants, goals.size()); return goals; } /** * Try to remove mutants per mutation operator until the number of mutants * is acceptable wrt the class limit */ private List getMutantsLimitedPerClass() { List mutants = MutationPool.getMutants(); String[] operators = { ReplaceVariable.NAME, InsertUnaryOperator.NAME, ReplaceConstant.NAME, ReplaceArithmeticOperator.NAME }; if(mutants.size() > Properties.MAX_MUTANTS_PER_CLASS) { for(String op : operators) { mutants.removeIf(u -> u.getMutationName().startsWith(op)); if(mutants.size() < Properties.MAX_MUTANTS_PER_CLASS) break; } } return mutants; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy