Merge pull request #55 from vzvu3k6k/bogo_sort_test

Add tests for Sorting/bogo_sort.rb and run tests on CI
This commit is contained in:
Vitor Oliveira 2020-12-28 09:00:53 -08:00 committed by GitHub
commit 8127d198ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 3 deletions

12
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,12 @@
name: test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-ruby@master
with:
ruby-version: '2.7'
- name: Run tests
run: rake test

View file

@ -42,6 +42,7 @@
## Sorting
* [Bogo Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bogo_sort.rb)
* [Bogo Sort Test](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bogo_sort_test.rb)
* [Bubble Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bubble_sort.rb)
* [Bucket Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/bucket_sort.rb)
* [Heap Sort](https://github.com/TheAlgorithms/Ruby/blob/master/sorting/heap_sort.rb)

7
Rakefile Normal file
View file

@ -0,0 +1,7 @@
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['**/*_test.rb']
end
task default: :test

View file

@ -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

16
sorting/bogo_sort_test.rb Normal file
View file

@ -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