def test_random_data(self): data = [random.randint(0,100) for _ in range(0,20)] sorted_data = copy.copy(data) sorted_data.sort() selectionsort.sort(data) self.assertEqual(data, sorted_data)
'name': 'Beau', 'age': 33 }, { 'name': 'Saron', 'age': 29 }] menu_choice = 0 print_menu() while menu_choice != 5: menu_choice = int(input("Type in a number (1-5): ")) if menu_choice == 1: sort_by = raw_input("Sort by name or age: ") while not (sort_by == 'name' or sort_by == 'age'): sort_by = raw_input("Must enter 'name' or 'age': ") selectionsort.sort(people, sort_by) for person in people: print(person) print('') elif menu_choice == 2: print("Add Contact") name = raw_input("Name: ") age = raw_input("Age: ") people.append({'name': name, 'age': int(age)}) elif menu_choice == 3: print("Remove Contact") name = raw_input("Name: ") removed = False for person in people: if person['name'] == name: people.remove(person)
def test_sort(): chaos = [12, 8, 8, 16, 4, 18, 6, 5, 16, 13, 17, 19, 5, 4, 7, 8, 4, 20, 5, 1, 19, 16, 12, 20, 4, 7, 1, 0, 6, 9, 11, 19, 4, 5, 14, 16, 1, 20, 5, 14, 18, 10, 0, 19, 11, 1, 2, 5, 15, 16] order = [0, 0, 1, 1, 1, 1, 2, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 9, 10, 11, 11, 12, 12, 13, 14, 14, 15, 16, 16, 16, 16, 16, 17, 18, 18, 19, 19, 19, 19, 20, 20, 20] result = sort(chaos) assert_equal(result, order)