From: Josh Cheek Date: 2009-12-30T07:05:42+09:00 Subject: Re: Creating my own method for sorting an array --000e0cd13a0a0090fa047be539b0 Content-Type: text/plain; charset=ISO-8859-1 Sigh, just so we can move on: If you run this, and the tests pass, then your sort function probably works. If you need a tip, here is the code I wrote to make it pass http://pastie.org/760568 require 'test/unit' def sort( unsorted , sorted = Array.new ) # your code here end def get_index_of_min( ary ) # your code here end class SortTest < Test::Unit::TestCase def test_single_chars assert_equal ['a','b','c','d'] , sort(['c', 'b', 'a', 'd']) end def test_double_chars assert_equal ['ab','cd','ef','gh','ij','kl'] , sort(['ab','kl','ij','cd','gh','ef']) end def test_numbers assert_equal [1,2,3,4] , sort([3,2,4,1]) end def test_empty_array assert_equal [] , sort([]) end def test_nil assert_equal nil , sort(nil) end end If you are running from the terminal, it should look something like this, if it completes correctly. If it does not, it will tell you which test failed, and show you what it expected to get, and what it actually got. $ ruby selection_sort.rb Loaded suite selection_sort Started ..... Finished in 0.000673 seconds. 5 tests, 5 assertions, 0 failures, 0 errors And for the record, I also don't think it makes sense to start writing tests before you know how to write code. Though I would agree that it should be taught earlier than it is (at my school, it isn't taught at all). --000e0cd13a0a0090fa047be539b0--