def test_sortFully(self): sortTest = SelectionSort(['abc', 1.0, 'ab', 'aa', 3, 1.2, 4, 'abb']) sortTest.sortFully() self.assertEqual(sortTest.unsorted, []) self.assertEqual(sortTest.sorted, [1.0, 1.2, 3, 4, 'aa', 'ab', 'abb', 'abc'])
def Main(array_to_be_sorted): acceptedTypes = [int, float, str] assert (type(array_to_be_sorted) == list ), "The input must be in the form of a list." for item in array_to_be_sorted: assert (type(item) in acceptedTypes), "Type %s unaccepted." % str(type(item)) assert array_to_be_sorted != [], "The array must not be empty." ## The code above is run before anything else ## to insure the input is formatted correctly. ## Can be edited if the accepted format/types change. sortChoice = input("\nWhich sorting algorith would you like to use?\n\n" + "1. Selection Sort\n" + "2. Insertion Sort\n\n" + "Insert your choice: ") if sortChoice == "1": temp = SelectionSort(array_to_be_sorted) temp.sortFully() return temp.sorted del temp elif sortChoice == "2": temp = InsertionSort(array_to_be_sorted) temp.sortFully() return temp.sorted del temp ## New sorting algorithms can be added ## by simply adding a new option in sortChoice ## and then adding a new elif statement here. else: raise ValueError("Invalid choice.")