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