Skip to content

Commit 50f02ce

Browse files
author
Tarang Khanna
committed
test case for merge sort in ruby and swift
do check the test case for ruby which i am not sure about
1 parent bc06e60 commit 50f02ce

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require './merge_sort'
2+
3+
describe "#merge_sort" do
4+
it "Sort The Array" do
5+
merge_sort([5,3,6,2,4]).should eq([2,3,3,5,6])
6+
end
7+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// merge_sort_test.swift
3+
//
4+
//
5+
// Created by Tarang khanna on 7/29/15.
6+
//
7+
//
8+
9+
import Foundation
10+
11+
func testBubbleSort() { // swift 1.2 compatible
12+
13+
let numberList : Array<Int> = [4, 3, 23, 2, 14, 41, 15,12]
14+
var mergeSortTest: merge_sort = merge_sort()
15+
16+
// pass the list to be sorted
17+
var resultList: Array<Int>! = mergeSortTest.mergesort(numberList)
18+
19+
// determine if the numbers are sorted
20+
var x: Int = 0
21+
for (x = 0; x < resultList.count; x++) {
22+
23+
if ((x > 0) && (resultList[x] < resultList[x - 1])) {
24+
XCTFail("numberlist items not in sorted order")
25+
}
26+
else {
27+
println("item \(resultList[x]) is sorted")
28+
}
29+
30+
31+
} // end for
32+
33+
34+
35+
} // end function
36+
37+
// supports all datatypes using generics

0 commit comments

Comments
 (0)