Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix formula types and add tarantula #243

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import fr.spoonlabs.flacoco.localization.spectrum.formulas.Formula;
import fr.spoonlabs.flacoco.localization.spectrum.formulas.OchiaiFormula;
import fr.spoonlabs.flacoco.localization.spectrum.formulas.TarantulaFormula;

public enum SpectrumFormula {

OCHIAI(new OchiaiFormula());
OCHIAI(new OchiaiFormula()),
TARANTULA(new TarantulaFormula());

private final Formula formula;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
/**
* Copyright (C) 2019 GZoltar contributors.
*
* This file is part of GZoltar.
*
* GZoltar 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 of
* the License, or (at your option) any later version.
*
* GZoltar 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
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with GZoltar. If
* not, see <https://www.gnu.org/licenses/>.
*/
package fr.spoonlabs.flacoco.localization.spectrum.formulas;

public interface Formula {

public double compute(int nPassingNotExecuting, int nFailingNotExecuting, int nPassingExecuting,
int nFailingExecuting);
public double compute(double nPassingNotExecuting, double nFailingNotExecuting, double nPassingExecuting,
double nFailingExecuting);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public class OchiaiFormula implements Formula {
public OchiaiFormula() {
}

public double compute(int nPassingNotExecuting, int nFailingNotExecuting, int nPassingExecuting,
int nFailingExecuting) {
public double compute(double nPassingNotExecuting, double nFailingNotExecuting, double nPassingExecuting,
double nFailingExecuting) {

if ((nFailingExecuting + nPassingExecuting == 0) || (nFailingExecuting + nFailingNotExecuting == 0)) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.spoonlabs.flacoco.localization.spectrum.formulas;

public class TarantulaFormula implements Formula {

public TarantulaFormula() {
}

public double compute(double nPassingNotExecuting, double nFailingNotExecuting, double nPassingExecuting,
double nFailingExecuting) {
double passingTerm = nPassingNotExecuting + nPassingExecuting == 0 ? 0 : nPassingExecuting / (nPassingNotExecuting + nPassingExecuting);
double failingTerm = nFailingNotExecuting + nFailingExecuting == 0 ? 0 : nFailingExecuting / (nFailingNotExecuting + nFailingExecuting);

if (passingTerm + failingTerm == 0) {
return 0;

Check warning on line 14 in src/main/java/fr/spoonlabs/flacoco/localization/spectrum/formulas/TarantulaFormula.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/fr/spoonlabs/flacoco/localization/spectrum/formulas/TarantulaFormula.java#L14

Added line #L14 was not covered by tests
}

return failingTerm / (passingTerm + failingTerm);
}

}
56 changes: 56 additions & 0 deletions src/test/java/fr/spoonlabs/flacoco/api/FlacocoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,62 @@ public void testExampleFL1SpectrumBasedOchiaiDefaultMode() {
assertOrdered(susp, locations);
}

@Test
public void testExampleFL1SpectrumBasedTarantulaDefaultMode() {
// Run only on target release >= 5
Assume.assumeTrue(getCompilerVersion() >= 5);

// Setup config
FlacocoConfig config = getDefaultFlacocoConfig();
config.setProjectPath(new File("./examples/exampleFL1/FLtest1").getAbsolutePath());
config.setSpectrumFormula(SpectrumFormula.TARANTULA);

// Run Flacoco
Flacoco flacoco = new Flacoco(config);

// Run default mode
FlacocoResult result = flacoco.run();

for (Map.Entry<Location, Suspiciousness> entry : result.getDefaultSuspiciousnessMap().entrySet()) {
System.out.println(entry);
}

// Check executed tests
assertEquals(4, result.getExecutedTests().size());
assertTrue(result.getExecutedTests().containsAll(Arrays.asList(
new StringTestMethod("fr.spoonlabs.FLtest1.CalculatorTest", "testMul"),
new StringTestMethod("fr.spoonlabs.FLtest1.CalculatorTest", "testDiv"),
new StringTestMethod("fr.spoonlabs.FLtest1.CalculatorTest", "testSubs"),
new StringTestMethod("fr.spoonlabs.FLtest1.CalculatorTest", "testSum")
)));

// Check failing tests
assertEquals(1, result.getFailingTests().size());
assertTrue(result.getFailingTests().contains(new StringTestMethod("fr.spoonlabs.FLtest1.CalculatorTest", "testMul")));

// Check ignored tests weren't executed
assertFalse(result.getExecutedTests().contains(new StringTestMethod("fr.spoonlabs.FLtest1.CalculatorTest", "testIgnore")));

Map<Location, Suspiciousness> susp = result.getDefaultSuspiciousnessMap();
assertEquals(6, susp.size());

// Line executed only by the failing
assertEquals(1.0, susp.get(new Location("fr.spoonlabs.FLtest1.Calculator", 15)).getScore(), 0);

// Line executed by a mix of failing and passing
assertEquals(0.75, susp.get(new Location("fr.spoonlabs.FLtest1.Calculator", 14)).getScore(), 0.01);
assertEquals(0.6, susp.get(new Location("fr.spoonlabs.FLtest1.Calculator", 12)).getScore(), 0.01);

// Lines executed by all test
assertEquals(0.5, susp.get(new Location("fr.spoonlabs.FLtest1.Calculator", 10)).getScore(), 0);
assertEquals(0.5, susp.get(new Location("fr.spoonlabs.FLtest1.Calculator", 5)).getScore(), 0);
assertEquals(0.5, susp.get(new Location("fr.spoonlabs.FLtest1.Calculator", 6)).getScore(), 0);

List<Location> locations = result.getSuspiciousLocationList();
assertEquals(6, locations.size());
assertOrdered(susp, locations);
}

@Test
public void testExampleFL1SpectrumBasedOchiaiDefaultModeThreshold() {
// Run only on target release >= 5
Expand Down
40 changes: 39 additions & 1 deletion src/test/java/fr/spoonlabs/flacoco/api/Math70Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void setUp() {
}

@Test
public void testMath70() {
public void testMath70Ochiai() {
// Setup config
FlacocoConfig config = new FlacocoConfig();
config.setProjectPath(new File("./examples/math_70").getAbsolutePath());
Expand Down Expand Up @@ -80,6 +80,44 @@ public void testMath70() {
assertEquals(0.5, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 87)).getScore(), 0);
}

@Test
public void testMath70Tarantula() {
// Setup config
FlacocoConfig config = new FlacocoConfig();
config.setProjectPath(new File("./examples/math_70").getAbsolutePath());
config.setWorkspace(workspaceDir.getRoot().getAbsolutePath());
config.setFamily(FlacocoConfig.FaultLocalizationFamily.SPECTRUM_BASED);
config.setSpectrumFormula(SpectrumFormula.TARANTULA);
config.setThreshold(0.5);

// Run Flacoco
Flacoco flacoco = new Flacoco(config);

// Run default mode
FlacocoResult result = flacoco.run();

for (Map.Entry<Location, Suspiciousness> entry : result.getDefaultSuspiciousnessMap().entrySet()) {
System.out.println(entry);
}

// TODO: Flacoco is only able of executing 2178 tests
//assertEquals(2181, result.getExecutedTests().size());
assertEquals(1, result.getFailingTests().size());

Map<Location, Suspiciousness> susp = result.getDefaultSuspiciousnessMap();
assertEquals(30, susp.size());

assertEquals(1.0, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 72)).getScore(), 0);
assertEquals(0.99, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 66)).getScore(), 0.01);
assertEquals(0.99, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 81)).getScore(), 0.01);
assertEquals(0.99, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 80)).getScore(), 0.01);
assertEquals(0.99, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 89)).getScore(), 0.01);
assertEquals(0.99, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 88)).getScore(), 0.01);
assertEquals(0.99, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 87)).getScore(), 0.01);
assertEquals(0.99, susp.get(new Location("org.apache.commons.math.analysis.solvers.BisectionSolver", 87)).getScore(), 0.01);
}



@Test
public void testMath70TestDetection() {
Expand Down
Loading