Skip to content

Instantly share code, notes, and snippets.

@hyzhak
Created June 8, 2012 12:37
Show Gist options
  • Save hyzhak/2895404 to your computer and use it in GitHub Desktop.
Save hyzhak/2895404 to your computer and use it in GitHub Desktop.
Compare two arrays with same contents, but with different order in hamcrest-as.
import org.hamcrest.assertThat;
import org.hamcrest.collection.arrayWithSize;
import org.hamcrest.collection.everyItem;
import org.hamcrest.collection.inArray;
/**
* Compare two arrays with same contents, but with different order in hamcrest-as.
*
* Does anybody have more shorter version?
*/
[Test]
public function testCompareTwoArraysWithSameContentButWithDifferentOrder() : void
{
var ar1 : Array = [1, 2, 3, 4];
var ar2 : Array = [2, 1, 4, 3];
assertThat(ar1, everyItem(inArray(ar2)));
assertThat(ar1, arrayWithSize(ar2.length));
}
@kimjianzsu
Copy link

How about following case? Can your test case catch it?
var ar1 : Array = [2, 2, 3, 4];
var ar2 : Array = [2, 1, 4, 3];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment