Skip to content

Instantly share code, notes, and snippets.

@diegocasmo
Created February 13, 2017 18:37
Show Gist options
  • Save diegocasmo/cca7c07152c611dde2cd376081d428cc to your computer and use it in GitHub Desktop.
Save diegocasmo/cca7c07152c611dde2cd376081d428cc to your computer and use it in GitHub Desktop.
Tests for an implementation of the Merge Sort algorithm in Ruby
require 'minitest/autorun'
require './merge_sort'
describe MergeSort do
before do
@merge_sort = MergeSort.new
end
describe "#sort" do
it "should sort an array of 1 element" do
assert_equal(@merge_sort.sort([1]), [1])
end
it "should sort an array of multiple elements" do
assert_equal(@merge_sort.sort([5, 2, 7, 8, 9, 3]), [2, 3, 5, 7, 8, 9])
end
it "should sort an array of multiple elements with equal slots" do
assert_equal(@merge_sort.sort([5, 5, 1, 3, 3, 7]), [1, 3, 3, 5, 5, 7])
end
it "should sort an array of multiple elements with negative numbers" do
assert_equal(@merge_sort.sort([-1, -4, 2, 0, -2, 7]), [-4, -2, -1, 0, 2, 7])
end
it "should sort an array of odd length" do
assert_equal(@merge_sort.sort([8, 3, 6, 2, 6, 8, 0]), [0, 2, 3, 6, 6, 8, 8])
end
end
end
@diegocasmo
Copy link
Author

The Merge Sort class being tested can be found here: https://gist.github.com/diegocasmo/b330010bd891c5581ee257f9aac87419

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment