문제

Java says that the following are not equal while they are:

java.lang.AssertionError: expected:<[[(7,UP), (2,RIGHT)], [(4,DOWN), (11,MIDDLE)], 
[(9,RIGHT), (1,UP)]]>
 but was:<[[(2,RIGHT), (7,UP)], [(11,MIDDLE), (4,DOWN)], [(1,UP), (9,RIGHT)]]>

(where each is a HashSet and each subset is another HashSet)

도움이 되었습니까?

해결책

No code is shown, so these are only guesses.

First, as mentioned, the elements of your Sets don't implement .equals()/.hashCode().

Second, you use assertEquals() on Collections: many test frameworks (TestNG for instance), when faced with Collections as arguments, will succeed if and only if the two collections have the same elements in the same order. Use another method, such as, for instance, assertEqualsNoOrder-) -- but here this is complicated by the fact that you have embedded Collections. Or just use assertTrue(coll1.equals(coll2)).

다른 팁

Most likely, the problem is that the equals() or hashCode() method of the type represented by (7,UP), etc., does not behave the way you expect.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top