From 2f53abe79881392940bf80a227e6e693c2dc6741 Mon Sep 17 00:00:00 2001 From: vzvu3k6k Date: Tue, 27 Oct 2020 05:35:41 +0900 Subject: [PATCH] Add tests for Sorting/bogo_sort.rb --- sorting/bogo_sort.rb | 8 +++++--- sorting/bogo_sort_test.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 sorting/bogo_sort_test.rb diff --git a/sorting/bogo_sort.rb b/sorting/bogo_sort.rb index c447cd5..c792026 100644 --- a/sorting/bogo_sort.rb +++ b/sorting/bogo_sort.rb @@ -13,6 +13,8 @@ class Array end end -puts "Enter a list of numbers separated by space" -str = gets.chomp.split('') -puts str.bogosort.join('') +if $0 == __FILE__ + puts "Enter a list of numbers separated by space" + str = gets.chomp.split('') + puts str.bogosort.join('') +end diff --git a/sorting/bogo_sort_test.rb b/sorting/bogo_sort_test.rb new file mode 100644 index 0000000..3fc6e83 --- /dev/null +++ b/sorting/bogo_sort_test.rb @@ -0,0 +1,16 @@ +require 'minitest/autorun' +require_relative './bogo_sort' + +class TestBogoSort < Minitest::Test + def test_sorted_array + input = [1, 2, 3, 4, 5] + expected = input.dup + assert_equal expected, input.bogosort + end + + def test_reversed_array + input = [5, 4, 3, 2, 1] + expected = [1, 2, 3, 4, 5] + assert_equal expected, input.bogosort + end +end