Skip to content

Commit

Permalink
fix the merge sort
Browse files Browse the repository at this point in the history
  • Loading branch information
xsank committed Jun 11, 2015
1 parent b57285c commit cc67864
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sort/merge_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ def merge(left,right):
return l
else:
middle=length/2
return merge(l[:middle],l[middle:])
return merge(merge_sort(l[:middle]),merge_sort(l[middle:]))

9 changes: 6 additions & 3 deletions sort/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
cases=[
[],
[1],
[1,3,1,4,21]
[1,3,1,4,21],
[3,1,2,4]
]

answers=[
[],
[1],
[1,1,3,4,21]
[1,1,3,4,21],
[1,2,3,4]
]

def test_sort(func):
Expand All @@ -31,7 +33,8 @@ def test_sort(func):
just because the bucket sort,count sort,radix sort.
'''
for index,case in enumerate(cases):
tmp_cases=[i[:] for i in cases]
for index,case in enumerate(tmp_cases):
try:
assert func(case)==answers[index]
except Exception:
Expand Down

0 comments on commit cc67864

Please sign in to comment.