Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

on the following code was supposed to calculate the total distance traveled. It

ID: 3789639 • Letter: O

Question

on the following code was supposed to calculate the total distance traveled. It does this by using the time and average speed from each of the three sections of a trip. This should be easy (for those who do not remember distance = time * speed), but the code contains a bug. Write a set of JUnit tests that provide 100% coverage of the RateCalculator class . If you do this, one (or more) of your tests should fail because of the error in my code. Now that you can see the error, go back and update RateCalculator to fix the error.

Code:

Explanation / Answer

}

Junit test:

The two classes need to be in the package edu.buffalo.cse116
1)import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestRateCalculator
{RateCalculator r=new RateCalculator();
x=r.totalDistance(2,5,10,1,20,2);
assertEquals(60,x,0.0);
}
2)import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
   public static void main(String[] args) {
      Result r = JUnitCore.runClasses(TestRateCalculator.class);
      
      for (Failure f:r.getFailures())
         System.out.println(f.toString());
      System.out.println(r.wasSuccessful());
}}