### Question:
CrashCoverageFitnessCalculator { protected double computeBranchDistance(BranchCoverageTestFitness branchFitness, ExecutionResult result){ ControlFlowDistance distance = branchFitness.getBranchGoal().getDistance(result); double value = distance.getResultingBranchFitness(); if (value == 0.0) { value = 1.0; } else { value = normalize(value); } return value; } CrashCoverageFitnessCalculator(StackTrace crash); double getLineCoverageFitness( ExecutionResult result , int lineNumber); double getLineCoverageForFrame( ExecutionResult result, int frameLevel); double calculateFrameSimilarity( StackTraceElement[] trace); double getFrameDistance(StackTraceElement targetFrame, StackTraceElement generatedFrame);  }### Answer:
@Test public void testComputeBranchDistance() { Map<Integer, Integer> lineCoverage = new HashMap<>(); lineCoverage.put(10, 1); Map<String, Map<Integer, Integer>> methodCoverage = new HashMap<>(); methodCoverage.put("method2", lineCoverage); ExecutionTrace executionTrace = new ExecutionTraceImpl(); Map<String, Map<String, Map<Integer, Integer>>> classCoverage = executionTrace.getCoverageData(); classCoverage.put("eu.stamp.ClassB", methodCoverage); ExecutionResult result = new ExecutionResult(new DefaultTestCase()); result.setTrace(executionTrace); ControlFlowDistance distance = new ControlFlowDistance(); distance.setApproachLevel(0); distance.setBranchDistance(1); BranchCoverageGoal goal = Mockito.mock(BranchCoverageGoal.class); Mockito.doReturn(distance).when(goal).getDistance(any(ExecutionResult.class)); BranchCoverageTestFitness fitness = new BranchCoverageTestFitness(goal); double fitnessValue = calculator.computeBranchDistance(fitness, result); assertEquals(1d / 3d, fitnessValue, 0.0001); }
@Test public void testComputeBranchDistance_zeroDistance() { Map<Integer, Integer> lineCoverage = new HashMap<>(); lineCoverage.put(10, 1); Map<String, Map<Integer, Integer>> methodCoverage = new HashMap<>(); methodCoverage.put("method2", lineCoverage); ExecutionTrace executionTrace = new ExecutionTraceImpl(); Map<String, Map<String, Map<Integer, Integer>>> classCoverage = executionTrace.getCoverageData(); classCoverage.put("eu.stamp.ClassB", methodCoverage); ExecutionResult result = new ExecutionResult(new DefaultTestCase()); result.setTrace(executionTrace); ControlFlowDistance distance = new ControlFlowDistance(); distance.setApproachLevel(0); distance.setBranchDistance(0); BranchCoverageGoal goal = Mockito.mock(BranchCoverageGoal.class); Mockito.doReturn(distance).when(goal).getDistance(any(ExecutionResult.class)); BranchCoverageTestFitness fitness = new BranchCoverageTestFitness(goal); double fitnessValue = calculator.computeBranchDistance(fitness, result); assertEquals(1.0, fitnessValue, 0.0001); }