Here is my JUnit code for a test case of the cube root method I created that implements Newton's method:
@Test
public void standardCase_negative64e9() {
double n = -64E9;
double result = csc143.newton.Roots.cbrt(n);
double delta = n * 1E-8;
assertEquals("Standard cube root -64E9", -4.0E3, result, delta);
}
When I do the tests for all my test cases (using DrJave IDE) I only get a failure for this test case, and it reads:
Failure: java.lang.AssertionError: Standard cube root -64E9 expected:<-4000.0> but
was:<-4000.0000000003124>
I feel this has something to do with my "delta" value (which is -640
in this case) because when I replace "delta" with 640
(instead of -640
) in the assertEquals()
method, I do not get a failure...