Created
October 27, 2011 13:25
-
-
Save ariejan/1319527 to your computer and use it in GitHub Desktop.
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
def sort(elements) | |
return elements if elements.size <= 1 | |
return elements if elements[0] < elements[1] | |
[elements[1], elements[0]] | |
end | |
describe "sort" do | |
example "empty array => empty array" do | |
sort([]).should == [] | |
end | |
example "one element array => one element array" do | |
sort([1]).should == [1] | |
end | |
example "two element array => two element array" do | |
sort([1,2]).should == [1,2] | |
sort([2,1]).should == [1,2] | |
end | |
example "three element array => three element array" do | |
sort([1,2,5]).should == [1,2,5] | |
sort([2,1,5]).should == [1,2,5] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment