Skip to content

Instantly share code, notes, and snippets.

@ackintosh
Created August 17, 2013 05:02
Show Gist options
  • Save ackintosh/6255357 to your computer and use it in GitHub Desktop.
Save ackintosh/6255357 to your computer and use it in GitHub Desktop.
gunmacs
require 'test/unit'
class Array
def bubble_sort
(0...(size)).each do |i|
((i + 1)...(size)).each do |j|
self[i], self[j] = self[j], self[i] if self[i] > self[j]
end
end
self
end
end
p [3, 5, 2, 9, 1, 10].bubble_sort
class ArrayTest < Test::Unit::TestCase
def test_buble_sort
assert_equal([], [].bubble_sort)
assert_equal([1, 2, 3, 5, 9, 10], [3, 5, 2, 9, 1, 10].bubble_sort)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment