Created
August 17, 2013 05:02
-
-
Save ackintosh/6255357 to your computer and use it in GitHub Desktop.
gunmacs
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
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