Created
June 8, 2012 12:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about following case? Can your test case catch it?
var ar1 : Array = [2, 2, 3, 4];
var ar2 : Array = [2, 1, 4, 3];