Search in sources :

Example 6 with TestSuiteLocalSearch

use of org.evosuite.testsuite.localsearch.TestSuiteLocalSearch in project evosuite by EvoSuite.

the class LocalSearchNumericSystemTest method runFloatExample.

private void runFloatExample(float x, float y) throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
    TestCase test = getFloatTest(x, y);
    TestSuiteChromosome suite = new TestSuiteChromosome();
    BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
    BranchCoverageMap.getInstance().searchStarted(null);
    assertEquals(4.0, fitness.getFitness(suite), 0.1F);
    suite.addTest(test);
    assertEquals(1.0, fitness.getFitness(suite), 0.1F);
    TestSuiteLocalSearch localSearch = TestSuiteLocalSearch.selectTestSuiteLocalSearch();
    LocalSearchObjective<TestSuiteChromosome> localObjective = new DefaultLocalSearchObjective<TestSuiteChromosome>();
    localObjective.addFitnessFunction(fitness);
    localSearch.doSearch(suite, localObjective);
    System.out.println("Fitness: " + fitness.getFitness(suite));
    System.out.println("Test suite: " + suite);
    assertEquals(0.0, fitness.getFitness(suite), 0.1F);
    BranchCoverageMap.getInstance().searchFinished(null);
}
Also used : TestSuiteLocalSearch(org.evosuite.testsuite.localsearch.TestSuiteLocalSearch) DefaultLocalSearchObjective(org.evosuite.ga.localsearch.DefaultLocalSearchObjective) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Aggregations

BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)6 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)6 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)6 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)6 TestSuiteLocalSearch (org.evosuite.testsuite.localsearch.TestSuiteLocalSearch)6 TestCase (org.evosuite.testcase.TestCase)4 DseBar (com.examples.with.different.packagename.localsearch.DseBar)2 DseFoo (com.examples.with.different.packagename.localsearch.DseFoo)2 Method (java.lang.reflect.Method)2 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)2 MethodStatement (org.evosuite.testcase.statements.MethodStatement)2 StringPrimitiveStatement (org.evosuite.testcase.statements.StringPrimitiveStatement)2 VariableReference (org.evosuite.testcase.variable.VariableReference)2 GenericClass (org.evosuite.utils.generic.GenericClass)2 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)2 GenericMethod (org.evosuite.utils.generic.GenericMethod)2 Test (org.junit.Test)2 EvoSuiteFile (org.evosuite.runtime.testdata.EvoSuiteFile)1 FileNamePrimitiveStatement (org.evosuite.testcase.statements.environment.FileNamePrimitiveStatement)1