Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created January 28, 2014 21:18
Show Gist options
  • Save apeiros/8676696 to your computer and use it in GitHub Desktop.
Save apeiros/8676696 to your computer and use it in GitHub Desktop.
Assert two enumerables to be equal, not minding the order
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