mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-11-16 19:50:00 +01:00
Add tests for selection sort
This commit is contained in:
parent
4ab2acac52
commit
d13fdb99f2
2 changed files with 18 additions and 3 deletions
|
@ -11,8 +11,12 @@ def selection_sort(array)
|
|||
array[i], array[smallest] = array[smallest], array[i] if i != smallest
|
||||
i += 1
|
||||
end
|
||||
array
|
||||
end
|
||||
|
||||
arr = [9, 8, 3, 1, 2, 55, 68, 48].shuffle # We have taken a rondom example and also shuffling it
|
||||
selection_sort(arr)
|
||||
puts "Sorted array is: #{arr.inspect}"
|
||||
if $0 == __FILE__
|
||||
puts 'Enter a list of numbers separated by space'
|
||||
|
||||
list = gets.split.map(&:to_i)
|
||||
p selection_sort(list)
|
||||
end
|
||||
|
|
11
sorting/selection_sort_test.rb
Normal file
11
sorting/selection_sort_test.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'minitest/autorun'
|
||||
require_relative './sort_tests'
|
||||
require_relative './selection_sort'
|
||||
|
||||
class TestSelectionSort < Minitest::Test
|
||||
include SortTests
|
||||
|
||||
def sort(input)
|
||||
selection_sort(input)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue