Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed-bug-in-mergesort-function #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fixed-bug-in-mergesort-function #81

wants to merge 1 commit into from

Conversation

parkershamblin
Copy link

Summary:

Found and fixed a small bug in the mergesort function inside sorting.py.

Changes:

Changed standard division to floor division to fix.

Results:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant