From fe52b262da3f3486ba8fc44a602df6b6bbcba517 Mon Sep 17 00:00:00 2001 From: vzvu3k6k Date: Sun, 14 Feb 2021 03:43:56 +0900 Subject: [PATCH] Add tests for bucket sort --- sorting/bucket_sort.rb | 9 ++++++--- sorting/bucket_sort_test.rb | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 sorting/bucket_sort_test.rb diff --git a/sorting/bucket_sort.rb b/sorting/bucket_sort.rb index 10b47a6..fbaad35 100644 --- a/sorting/bucket_sort.rb +++ b/sorting/bucket_sort.rb @@ -19,7 +19,10 @@ def bucket_sort(array, bucket_size = DEFAULT_BUCKET_SIZE) buckets.flatten end -puts 'Enter a list of numbers separated by space' -list = gets -print bucket_sort(list) +if $0 == __FILE__ + puts 'Enter a list of numbers separated by space' + + list = gets.split.map(&:to_i) + p bucket_sort(list) +end diff --git a/sorting/bucket_sort_test.rb b/sorting/bucket_sort_test.rb new file mode 100644 index 0000000..148d8fc --- /dev/null +++ b/sorting/bucket_sort_test.rb @@ -0,0 +1,11 @@ +require 'minitest/autorun' +require_relative './sort_tests' +require_relative './bucket_sort' + +class TestBucketSort < Minitest::Test + include SortTests + + def sort(input) + bucket_sort(input) + end +end