Java JUnit: The method X is ambiguous for type Y

后端 未结 3 1688
小蘑菇
小蘑菇 2020-12-13 03:24

I had some tests working fine. Then, I moved it to a different package, and am now getting errors. Here is the code:

import static org.junit.Assert.*;
import         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 03:42

    You can use the method

    assertEquals(double expected, double actual, double delta)
    

    Which will take into account rounding error that are hinerent to floating point (see this post for example). You can write

    assertEquals(70, eccen.get("alpha"), 0.0001);
    

    This mean that as long as the two values differ for less than 0.0001 they are considered to be equals. This has two advantages:

    • Compares floating point values as they are supposed to
    • No need to cast, as the three argument assert only applyes to doubles, not to generic Objects

提交回复
热议问题