mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-02-05 08:46:12 +01:00
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:
commit
8127d198ea
5 changed files with 41 additions and 3 deletions
12
.github/workflows/test.yml
vendored
Normal file
12
.github/workflows/test.yml
vendored
Normal 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
|
|
@ -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
7
Rakefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.test_files = FileList['**/*_test.rb']
|
||||
end
|
||||
|
||||
task default: :test
|
|
@ -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
16
sorting/bogo_sort_test.rb
Normal 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
|
Loading…
Add table
Reference in a new issue