This notebook was prepared by Donne Martin. Source and license info is on GitHub.
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class QuickSort(object):
def sort(self, data):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_quick_sort.py
import unittest
class TestQuickSort(unittest.TestCase):
def test_quick_sort(self):
quick_sort = QuickSort()
print('None input')
self.assertRaises(TypeError, quick_sort.sort, None)
print('Empty input')
self.assertEqual(quick_sort.sort([]), [])
print('One element')
self.assertEqual(quick_sort.sort([5]), [5])
print('Two or more elements')
data = [5, 1, 7, 2, 6, -3, 5, 7, -1]
self.assertEqual(quick_sort.sort(data), sorted(data))
print('Success: test_quick_sort\n')
def main():
test = TestQuickSort()
test.test_quick_sort()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.