Found and fixed small bug in mergesort function of sorting.py. Changed standard division to floor division to fix.
Results of running sorting.py BEFORE change:
Trying:
bubblesort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
Trying:
insertionsort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
Trying:
mergesort([5, 4, 1, 6, 2, 3, 9, 7])
Expecting:
[1, 2, 3, 4, 5, 6, 7, 9]
**********************************************************************
File "c:/Users/parker/Documents/GitHub/Algorithms/sorting and basics/sorting.py", line 4, in __main__.mergesort
Failed example:
mergesort([5, 4, 1, 6, 2, 3, 9, 7])
Exception raised:
Traceback (most recent call last):
File "C:\Users\parker\Anaconda3\lib\doctest.py", line
1329, in __run
compileflags, 1), test.globs)
File "<doctest __main__.mergesort[0]>", line 1, in <module>
mergesort([5, 4, 1, 6, 2, 3, 9, 7])
File "c:/Users/parker/Documents/GitHub/Algorithms/sorting and basics/sorting.py", line 12, in mergesort
a1 = mergesort(arr[:n/2])
TypeError: slice indices must be integers or None or have an __index__ method
Trying:
mergesort([3, 2, 4, 2, 1])
Expecting:
[1, 2, 2, 3, 4]
**********************************************************************
File "c:/Users/parker/Documents/GitHub/Algorithms/sorting and basics/sorting.py", line 7, in __main__.mergesort
Failed example:
mergesort([3, 2, 4, 2, 1])
Exception raised:
Traceback (most recent call last):
File "C:\Users\parker\Anaconda3\lib\doctest.py", line
1329, in __run
compileflags, 1), test.globs)
File "<doctest __main__.mergesort[1]>", line 1, in <module>
mergesort([3, 2, 4, 2, 1])
File "c:/Users/parker/Documents/GitHub/Algorithms/sorting and basics/sorting.py", line 12, in mergesort
a1 = mergesort(arr[:n/2])
TypeError: slice indices must be integers or None or have an __index__ method
Trying:
quicksort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
Trying:
selectionsort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
2 items had no tests:
__main__
__main__.merge
4 items passed all tests:
1 tests in __main__.bubblesort
1 tests in __main__.insertionsort
1 tests in __main__.quicksort
1 tests in __main__.selectionsort
**********************************************************************
1 items had failures:
2 of 2 in __main__.mergesort
6 tests in 7 items.
4 passed and 2 failed.
***Test Failed*** 2 failures.
Results of running sorting.py AFTER change:
Trying:
bubblesort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
Trying:
insertionsort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
Trying:
mergesort([5, 4, 1, 6, 2, 3, 9, 7])
Expecting:
[1, 2, 3, 4, 5, 6, 7, 9]
ok
Trying:
mergesort([3, 2, 4, 2, 1])
Expecting:
[1, 2, 2, 3, 4]
ok
Trying:
quicksort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
Trying:
selectionsort([6, 4, 8, 2, 1, 9, 10])
Expecting:
[1, 2, 4, 6, 8, 9, 10]
ok
2 items had no tests:
main
main.merge
5 items passed all tests:
1 tests in main.bubblesort
1 tests in main.insertionsort
2 tests in main.mergesort
1 tests in main.quicksort
1 tests in main.selectionsort
6 tests in 7 items.
6 passed and 0 failed.
Test passed.