Created
January 28, 2014 21:18
-
-
Save apeiros/8676696 to your computer and use it in GitHub Desktop.
Assert two enumerables to be equal, not minding the order
This file contains hidden or 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
module Test::Unit::Assertions | |
def assert_unordered_equal(expected, actual, message=nil) | |
full_message = build_message(message, "<?> expected but was\n<?>.\n", expected, actual) | |
assert_block(full_message) { | |
seen = Hash.new(0) | |
expected.each { |e| seen[e] += 1 } | |
actual.each { |e| seen[e] -= 1 } | |
seen.invert.keys == [0] | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment