mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-15 03:43:22 +01:00
31 lines
666 B
Ruby
31 lines
666 B
Ruby
|
# SortTests provides general test cases for sorting function.
|
||
|
# By using this module, tests can be implemented like this:
|
||
|
#
|
||
|
# class TestBuiltinSort < Minitest::Test
|
||
|
# # SortTests adds some test_* methods.
|
||
|
# include SortTests
|
||
|
#
|
||
|
# # SortTests requires sort method.
|
||
|
# def sort(input)
|
||
|
# input.sort
|
||
|
# end
|
||
|
# end
|
||
|
|
||
|
module SortTests
|
||
|
def sort(input)
|
||
|
raise NotImplementedError
|
||
|
end
|
||
|
|
||
|
def test_sorted_array
|
||
|
input = [1, 2, 3, 4, 5]
|
||
|
expected = input.dup
|
||
|
assert_equal expected, sort(input)
|
||
|
end
|
||
|
|
||
|
def test_reversed_array
|
||
|
input = [5, 4, 3, 2, 1]
|
||
|
expected = [1, 2, 3, 4, 5]
|
||
|
assert_equal expected, sort(input)
|
||
|
end
|
||
|
end
|