Skip to content

Commit c81146e

Browse files
committed
sorting algos
1 parent 91997b4 commit c81146e

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

sorting_algos/bubble_sort.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include RSpec
2+
require 'pry'
3+
4+
def bubble_sort(array)
5+
end

sorting_algos/bubble_sort_spec.rb

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
include RSpec
2+
require_relative 'bubble_sort'
3+
4+
RSpec.describe MyStack, type: Class do
5+
describe "#bubble_sort" do
6+
it "moves the largest integer to the end of the array" do
7+
expect( bubble_sort([6,2,5,3,4]) ).to end_with 6
8+
end
9+
10+
it "moves the smallest integer to the front of the array" do
11+
expect( bubble_sort([6,2,5,3,4]) ).to start_with 2
12+
end
13+
14+
it "handles an empty array" do
15+
expect( bubble_sort([]) ).to eq []
16+
end
17+
18+
it "handles an array of length one" do
19+
expect( bubble_sort([1]) ).to eq [1]
20+
end
21+
22+
let (:sorted_array) { [1,2,3,4,5,6] }
23+
let (:shuffled_array) { sorted_array.shuffle }
24+
25+
it "sorts the array from least to greatest" do
26+
expect( bubble_sort([6,2,5,3,4]) ).to eq [2,3,4,5,6]
27+
expect( bubble_sort(shuffled_array) ).to eq sorted_array
28+
end
29+
30+
it "handles zero appropriately" do
31+
expect( bubble_sort([6,2,5,3,4,0]) ).to start_with 0
32+
end
33+
34+
it "handles negative numbers appropriately" do
35+
expect( bubble_sort([6,2,-11, 5,3,4]) ).to start_with -11
36+
end
37+
end
38+
end

sorting_algos/bucket_sort.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include RSpec
2+
require 'pry'
3+
4+
def bucket_sort(array)
5+
end

sorting_algos/bucket_sort_spec.rb

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
include RSpec
2+
require_relative 'bucket_sort'
3+
4+
RSpec.describe MyStack, type: Class do
5+
describe "#bucket_sort" do
6+
it "moves the largest integer to the end of the array" do
7+
expect( bucket_sort([6,2,5,3,4]) ).to end_with 6
8+
end
9+
10+
it "moves the smallest integer to the front of the array" do
11+
expect( bucket_sort([6,2,5,3,4]) ).to start_with 2
12+
end
13+
14+
it "handles an empty array" do
15+
expect( bucket_sort([]) ).to eq []
16+
end
17+
18+
it "handles an array of length one" do
19+
expect( bucket_sort([1]) ).to eq [1]
20+
end
21+
22+
let (:sorted_array) { [1,2,3,4,5,6] }
23+
let (:shuffled_array) { sorted_array.shuffle }
24+
25+
it "sorts the array from least to greatest" do
26+
expect( bucket_sort([6,2,5,3,4]) ).to eq [2,3,4,5,6]
27+
expect( bucket_sort(shuffled_array) ).to eq sorted_array
28+
end
29+
30+
it "handles zero appropriately" do
31+
expect( bucket_sort([6,2,5,3,4,0]) ).to start_with 0
32+
end
33+
34+
it "handles negative numbers appropriately" do
35+
expect( bucket_sort([6,2,-11, 5,3,4]) ).to start_with -11
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)