Question
Python programming Purpose: To practice writing test cases and implementing a test driver for a familiar sorting algorithm. In the provided le a8q3_functions.py youll nd
Python programming
Purpose: To practice writing test cases and implementing a test driver for a familiar sorting algorithm. In the provided le a8q3_functions.py youll nd the function: quickSort(): Given an unsorted list of sortable elements, returns a new sorted list in ascending (smallest to largest) order. The code is also shown below with the docstring removed to save space. This is a Python implementation of the quick sort algorithm studied in chapter 17. ------------------------------------------------------------------------------------ def quickSort ( unsorted ): # if unsorted contains 0 or 1 items , it s already sorted if len( unsorted ) <= 1: return unsorted # divide step of quick sort L = [] # for items smaller than the pivot E = [] # for items equal to the pivot G = [] # for items greater than the pivot p = unsorted [0] # first data item is the pivot for i in range (0, len( unsorted ) -1): if unsorted [i] < p: L. append ( unsorted [i]) elif unsorted [i] > p: G. append ( unsorted [i]) else : E. append ( unsorted [i]) # recursively solve subproblems of sorting L and G G = quickSort (L) L = quickSort (G) # re - assemble the sublists sortedList = [] sortedList . append (L) sortedList . append (E) sortedList . append (G) return sortedList
--------------------------------------------------------------------------------------------------
This function contains errors. Your task will be to nd the errors by systematically testing. Youll hand in an explanation of what the errors are, and how you xed them, but you will not hand in the corrected code. 1. Write white-box and black-box tests for the function quickSort(). You should do this without Python, either on paper, or in a simple document. Dont worry about running your tests until you have thought about which test cases you want. Make sure you have at least 3 black-box tests and 3 white-box tests. More tests may be useful. 2. Implement a test driver using your test cases in a document named a8q3_testing.py. This should be done using the techniques seen in the textbook (Chapter 15) and as demonstrated in class (Chapter 15 Exercise 3). 3. Run your tests and copy/paste the console output to a document named a8q3_output.txt. The console output you hand in should come from the program before you try to x it! 4. Try to deduce the problems with the quickSort() function from the output of your testing. Once you have an idea of what is wrong, x the errors in the function so that your test driver does not indicate any faults. 5. In the document a8q3_output.txt, describe the error(s) you found and how you xed it (them). You do not need to write a lot; a sentence or two for each error is all we want. Write your explanation as if you are explaining the error to a colleague of yours who wrote the function
---------------------------------------------------------------------------------------------------------------------------------
START File a8q3_functions.py
def quickSort(unsorted): """ Sorts an unsorted list using the Quick Sort algorithm :param unsorted: list of sortable elements :return: one new list with all elements of unsorted_list in ascending order """ # if unsorted contains 0 or 1 items, it's already sorted if len(unsorted) <= 1: return unsorted # divide step of quick sort L = [] # for items smaller than the pivot E = [] # for items equal to the pivot G = [] # for items greater than the pivot p = unsorted[0] # first data item is the pivot for i in range(0, len(unsorted)-1): if unsorted[i] < p: L.append(unsorted[i]) elif unsorted[i] > p: G.append(unsorted[i]) else: E.append(unsorted[i]) # recursively solve subproblems of sorting L and G G = quickSort(L) L = quickSort(G) # re-assemble the sublists sortedList = [] sortedList.append(L) sortedList.append(E) sortedList.append(G) return sortedList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started