Search in sources :

Example 16 with DefaultLocalSearchObjective

use of org.evosuite.ga.localsearch.DefaultLocalSearchObjective in project evosuite by EvoSuite.

the class LocalSearchNumericSystemTest method runIntExample.

private void runIntExample(int x, int y) throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
    TestCase test = getIntTest(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)

Example 17 with DefaultLocalSearchObjective

use of org.evosuite.ga.localsearch.DefaultLocalSearchObjective 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

DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)17 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)17 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)17 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)16 Test (org.junit.Test)13 Properties (org.evosuite.Properties)10 TestChromosome (org.evosuite.testcase.TestChromosome)10 TestSuiteLocalSearch (org.evosuite.testsuite.localsearch.TestSuiteLocalSearch)6 Foo (com.examples.with.different.packagename.symbolic.Foo)4 TestCase (org.evosuite.testcase.TestCase)4 DseBar (com.examples.with.different.packagename.localsearch.DseBar)2 DseFoo (com.examples.with.different.packagename.localsearch.DseFoo)2 Flag (com.examples.with.different.packagename.ncs.Flag)2 Loops (com.examples.with.different.packagename.ncs.Loops)2 Triangle (com.examples.with.different.packagename.ncs.Triangle)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