Skip to content

Instantly share code, notes, and snippets.

@ninjudd
Created September 24, 2010 00:19
Show Gist options
  • Save ninjudd/594653 to your computer and use it in GitHub Desktop.
Save ninjudd/594653 to your computer and use it in GitHub Desktop.
def test_get_some_with_validation
100.times do |i|
i = -i if i.odd?
m.set(i.to_s, i)
assert_equal i, m.get(i.to_s)
end
keys = (0...100).collect {|key| key.to_s}
results = m.get_some(keys, :validation => lambda {|k,v| k.to_i == v}) do |missing_keys|
assert_equal 50, missing_keys.size
r = {}
missing_keys.each do |key|
r[key] = key.to_i
end
r
end
assert_equal 100, results.size
results.each do |key, value|
assert_equal key.to_i, value
end
results = m.get_some(keys, :validation => lambda {|k,v| k.to_i == v}) do |missing_keys|
flunk "no values should be invalid"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment