Skip to content

Instantly share code, notes, and snippets.

@kirel
Created September 10, 2009 13:42
Show Gist options
  • Select an option

  • Save kirel/184555 to your computer and use it in GitHub Desktop.

Select an option

Save kirel/184555 to your computer and use it in GitHub Desktop.
class Array
def delete_at_random l
res = []
l.times { res << delete_at(rand(size)) }
res
end
end
if __FILE__ == $0
require "test/unit"
class TestSomeModel < Test::Unit::TestCase
def setup
@array = (1..100).to_a
@original = @array.dup
@num = 5
end
def test_delete_at_random_gives_me_a_slice
slice = @array.delete_at_random(@num)
assert_instance_of(Array, slice)
assert slice.all? { |e| @original.include? e }
end
def test_delete_at_random_deletes_result
slice = @array.delete_at_random(@num)
assert !slice.all? { |e| @array.include? e }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment