Search in sources :

Example 51 with BranchCoverageSuiteFitness

use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness 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 52 with BranchCoverageSuiteFitness

use of org.evosuite.coverage.branch.BranchCoverageSuiteFitness 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)52 Test (org.junit.Test)45 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)44 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)18 TestCase (org.evosuite.testcase.TestCase)17 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)16 TestChromosome (org.evosuite.testcase.TestChromosome)14 Properties (org.evosuite.Properties)12 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)12 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)12 Method (java.lang.reflect.Method)11 GenericMethod (org.evosuite.utils.generic.GenericMethod)11 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)10 ArrayList (java.util.ArrayList)8 BranchCoverageFactory (org.evosuite.coverage.branch.BranchCoverageFactory)7 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)7 VariableReference (org.evosuite.testcase.variable.VariableReference)7 GenericClass (org.evosuite.utils.generic.GenericClass)7 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)7 Foo (com.examples.with.different.packagename.symbolic.Foo)6