Conversation
|
Your fix looks too big, do you even need different orders of array elements? |
|
IMO it depends on the semantics.
To me, a typical set or map can produce elements in arbitrary order by definition. Fixing the tests by describing the output space is then desirable, despite the missing elegance of the code. I was using an enumerator in Python to synthesize all conditions. Nonetheless, to simplify code one may implement the enumeration in Java. More concretely, something like: @Test
public void testToString() {
if (!isAddSupported()) {
return;
}
final MultiValuedMap<K, V> map = makeObject();
map.put((K) "A", (V) "X");
map.put((K) "A", (V) "Y");
map.put((K) "A", (V) "Z");
map.put((K) "B", (V) "U");
map.put((K) "B", (V) "V");
map.put((K) "B", (V) "W");
List<String> permutations = new ArrayList<>();
for (List<Character> e : permute("XYZ", 3)) {
for (List<Character> c : permute("UVW", 3)) {
String permutation = "{B=" + c + ", A=" + e + "}";
permutations.add("{B=" + c + ", A=" + e + "}");
permutations.add("{A=" + e + ", B=" + c + "}");
}
}
assertTrue(permutations.contains(map.toString()));
} |
|
Even let's look at the
https://docs.oracle.com/javase/8/docs/api/java/util/AbstractCollection.html#toString--
Therefore, we have: |
|
test1 test3 |
About
This PR fixes a flaky test brought by the
toStringmethod applied to theMultiValuedMapclass.What this PR is doing and why
The
toStringof theMultiValuedMapclass is designed to produce elements printed in non-deterministic but still readable order. To preserve the semantics while removing the flakiness, this PR simply enumerates the output space and lists them as correct answers. That being said, as long as the printed output ofMultiValuedMapis one of the listed possibilities, the test can pass.