diff --git a/nondex-test/src/test/java/edu/illinois/nondex/core/AbstractCollectionTest.java b/nondex-test/src/test/java/edu/illinois/nondex/core/AbstractCollectionTest.java index 028f849d..faec7293 100644 --- a/nondex-test/src/test/java/edu/illinois/nondex/core/AbstractCollectionTest.java +++ b/nondex-test/src/test/java/edu/illinois/nondex/core/AbstractCollectionTest.java @@ -29,6 +29,8 @@ a copy of this software and associated documentation files (the package edu.illinois.nondex.core; +import java.util.Arrays; + import edu.illinois.nondex.shuffling.ControlNondeterminism; import org.junit.Assert; @@ -56,16 +58,22 @@ protected void assertParameterized(T ds, Object derived, String str) { } } - protected void assertEqualstUnordered(String msg, String expected, String actual) { - Assert.assertEquals(msg + ": " + expected + " =/= " + actual, expected.length(), actual.length()); - String trimmed = expected.substring(1, expected.length() - 1); + private String[] formatString(String msg) { + String trimmed = msg.substring(1, msg.length() - 1); String[] elems = trimmed.split(","); - // TODO(gyori): fix and make this more robust. It does not check duplicates, substrings, etc. for (int i = 0; i < elems.length; i++) { elems[i] = elems[i].trim(); - Assert.assertTrue(msg + ": " + trimmed + " =/= " + actual, actual.contains(elems[i])); } + return elems; + } + protected void assertEqualstUnordered(String msg, String expected, String actual) { + String trimmed = expected.substring(1, expected.length() - 1); + String[] actualTokenized = this.formatString(actual); + String[] expectedTokenized = this.formatString(expected); + Arrays.sort(actualTokenized); + Arrays.sort(expectedTokenized); + Assert.assertArrayEquals(msg + ": " + trimmed + " =/= " + actual, expectedTokenized, actualTokenized); } } diff --git a/nondex-test/src/test/java/edu/illinois/nondex/core/HashMapTest.java b/nondex-test/src/test/java/edu/illinois/nondex/core/HashMapTest.java index 9fc689d0..7ec0294b 100644 --- a/nondex-test/src/test/java/edu/illinois/nondex/core/HashMapTest.java +++ b/nondex-test/src/test/java/edu/illinois/nondex/core/HashMapTest.java @@ -148,6 +148,12 @@ public void testEntrySet() { "{0=0, 1=1, 2=2, 3=3, 4=4, 5=5, 6=6, 7=7, 8=8, 9=9}", entrySet.toString()); } + @Test(expected = AssertionError.class) + public void testAssertEqualsUnorderedFailsWithDuplicates() { + this.assertEqualstUnordered("the strings are not a permutation of each other", + "{0=0, 0=0, 1=1, 2=2, 3=3}", "{0=0, 1=1, 2=2, 3=3}"); + } + @Test public void testEntrySetParametrized() { Map map = this.createResizedDS();