### Question:
CrashCoverageFitnessCalculator { public double getFrameDistance(StackTraceElement targetFrame, StackTraceElement generatedFrame){ String className =targetFrame.getClassName(); if(className.contains("$") & !className.equals(generatedFrame.getClassName())){ className = targetFrame.getClassName().split("\\$")[0]; } double elementDistance; if (!className.equals(generatedFrame.getClassName())){ elementDistance = 3.0; }else if (!targetFrame.getMethodName().equals(generatedFrame.getMethodName())) { elementDistance = 2.0; }else{ elementDistance = normalize(Math.abs(targetFrame.getLineNumber() - generatedFrame.getLineNumber())); } return normalize(elementDistance); } 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 testGetFrameDistance_zeroDistance() { StackTraceElement generated = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", 10); StackTraceElement target = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", 10); double distance = calculator.getFrameDistance(generated, target); assertEquals(0.0, distance, 0.000001); }
@Test public void testGetFrameDistance_differentClass() { StackTraceElement generated = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", 10); StackTraceElement target = new StackTraceElement("eu.stamp.ClassB", "method2", "ClassA", 10); double distance = calculator.getFrameDistance(generated, target); assertEquals(0.75, distance, 0.000001); }
@Test public void testGetFrameDistance_differentMethod() { StackTraceElement generated = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", 10); StackTraceElement target = new StackTraceElement("eu.stamp.ClassA", "method1", "ClassA", 10); double distance = calculator.getFrameDistance(generated, target); assertEquals(2.0 / 3.0, distance, 0.000001); }
@Test(expected = java.lang.IllegalArgumentException.class) public void testNormalize() { StackTraceElement generated = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", Integer.MAX_VALUE); StackTraceElement target = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", -1); double distance = calculator.getFrameDistance(generated, target); assertEquals(1.0 / 2.0, distance, 0.000001); }