### Question:
CrashCoverageFitnessCalculator { public double calculateFrameSimilarity( StackTraceElement[] trace) { return calculateFrameSimilarity(trace, targetCrash); } 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 testCalculateFrameSimilarity_zeroDistance() throws IOException { BufferedReader obj = new BufferedReader(new StringReader("java.lang.IllegalArgumentException:\n" + "\tat eu.stamp.ClassA.method2(ClassA.java:10)\n" + "\tat eu.stamp.ClassB.method1(ClassB.java:20)")); StackTrace target = Mockito.spy(new StackTrace()); Mockito.doReturn(obj).when(target).readFromFile(anyString()); target.setup("", 2); StackTraceElement[] trace = new StackTraceElement[2]; trace[0] = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", 10); trace[1] = new StackTraceElement("eu.stamp.ClassB", "method1", "ClassB", 20); CrashCoverageFitnessCalculator calculator = new CrashCoverageFitnessCalculator(target); double distance = calculator.calculateFrameSimilarity(trace, target); assertEquals(0, distance, 0.000001); }
@Test public void testCalculateFrameSimilarity_nonZeroDistance() throws IOException { BufferedReader obj = new BufferedReader(new StringReader("java.lang.IllegalArgumentException:\n" + "\tat eu.stamp.ClassA.method2(ClassA.java:10)\n" + "\tat eu.stamp.ClassB.method1(ClassB.java:20)")); StackTrace target = Mockito.spy(new StackTrace()); Mockito.doReturn(obj).when(target).readFromFile(anyString()); target.setup("", 2); StackTraceElement[] trace = new StackTraceElement[2]; trace[0] = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", 10); trace[1] = new StackTraceElement("eu.stamp.ClassB", "method1", "ClassB", 21); double distance = calculator.calculateFrameSimilarity(trace, target); assertEquals(0.25, distance, 0.000001); }
@Test public void testCalculateFrameSimilarity_containsExtraRows() throws IOException { BufferedReader obj = new BufferedReader(new StringReader("java.lang.IllegalArgumentException:\n" + "\tat eu.stamp.ClassA.method2(ClassA.java:10)\n" + "\tat eu.stamp.ClassB.method1(ClassB.java:20)" + "\tat eu.stamp.ClassB.invoke(ClassB.java:20)" + "\tat eu.stamp.ClassB.reflect(ClassB.java:20)" + "\tat eu.stamp.evosuite.Evosuite(Evosuite.java:20)")); StackTrace target = Mockito.spy(new StackTrace()); Mockito.doReturn(obj).when(target).readFromFile(anyString()); target.setup("", 2); CrashCoverageFitnessCalculator calculator = new CrashCoverageFitnessCalculator(target); StackTraceElement[] trace = new StackTraceElement[2]; trace[0] = new StackTraceElement("eu.stamp.ClassA", "method2", "ClassA", 10); trace[1] = new StackTraceElement("eu.stamp.ClassB", "method1", "ClassB", 20); double distance = calculator.calculateFrameSimilarity(trace, target); assertEquals(0.0, distance, 0.000001); }