def test_issorted(self): collection = utils.sorted_list(1, 1000) result = sorting.isSorted(collection) self.assertEqual(True, result) collection = utils.reversed_sorted_list(1, 1000) result = sorting.isSorted(collection) self.assertEqual(False, result)
def second_user_input(): user_input = input('What section would you like to run?\n\ [1]List of first 5 items sorted by Current Rent\n\ [2]List of all mast data where the Lease Years is 25 + the Total Rent for the Properties in the list\n\ [3]A Dictionary of all the Tenants and the count of masts for each\n\ [4]List of all mast data where the Lease Start Date is between 1st of June 1999 and 31st of August 2007\n\ ') if user_input == '1': print(sorted_list(read_csv(), 'Current Rent')[:5]) elif user_input == '2': print(master_list_filtered(read_csv(), 'Lease Years', '25')) print('Total Rent: ' + str( calculate_total_rent( master_list_filtered(read_csv(), 'Lease Years', '25')))) elif user_input == '3': print(count_total_masts_by_tenant(read_csv())) elif user_input == '4': print( tenant_data_between_dates(read_csv(), '01-Jun-1999', '31-Aug-2007')) else: print('Sorry, your selection is not valid, please try again.\n') second_user_input()
def test_quick_sort_rec(self): collection = utils.random_list(10000, 1, 1000) result = sorting.qs(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted) collection = utils.reversed_sorted_list(1, 10000) result = sorting.quick_sort_rec(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted) collection = utils.sorted_list(1, 10000) result = sorting.quick_sort_rec(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted)
def test_merge_sort(self): collection = utils.random_list(10000, 1, 1000) result = sorting.merge_sort(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted) collection = utils.reversed_sorted_list(1, 10000) result = sorting.merge_sort(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted) collection = utils.sorted_list(1, 10000) result = sorting.merge_sort(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted)
def test_quick_sort_inplace(self): collection = utils.random_list(10000, 1, 1000) sorting.qs_inplace(collection) is_sorted = sorting.isSorted(collection) self.assertEqual(True, is_sorted) collection = utils.reversed_sorted_list(1, 10000) sorting.qs_inplace(collection) is_sorted = sorting.isSorted(collection) self.assertEqual(True, is_sorted) collection = utils.sorted_list(1, 10000) sorting.qs_inplace(collection) is_sorted = sorting.isSorted(collection) self.assertEqual(True, is_sorted)
def test_binary_search(self): collection = utils.sorted_list(1, 1000) result = algorithm_easy.binary_search(4, collection) self.assertEqual(3, result) result = algorithm_easy.binary_search(0, collection) self.assertEqual(-1, result) collection = [] result = algorithm_easy.binary_search(10, collection) self.assertEqual(-1, result) collection = [1] result = algorithm_easy.binary_search(1, collection) self.assertEqual(0, result) collection = [1, 2] result = algorithm_easy.binary_search(2, collection) self.assertEqual(1, result) result = algorithm_easy.binary_search(3, collection) self.assertEqual(-1, result)
def test_binary_tree(self): l = utils.sorted_list(0, 7) # Creation b = btree.BinTree() while l: b.tinsert(utils.takeRdm(l)) # Functions result = b.treeSort() is_sorted = isSorted(result) self.assertEqual(True, is_sorted) b.treeMap(b.getRoot(), lambda x: x + 1) for idx, elem in enumerate(b.treeSort()): self.assertTrue(result[idx] < elem) # Search/Min/Max b.tinsert(16) searched = b.search(b.getRoot(), 16) self.assertEqual(btree.Node(16), searched) mi = b.minimum(b.getRoot()) self.assertEqual(1, mi) ma = b.maximum(b.getRoot()) self.assertEqual(16, ma)
def first_user_input(): user_input = input( 'Hi, would you like to run the whole script, or just a section?\n\ [1] Whole Script\n\ [2] Specific Section\n\ ') if user_input == '1': print(sorted_list(read_csv(), 'Current Rent')[:5]) print(master_list_filtered(read_csv(), 'Lease Years', '25')) print('Total Rent: ' + str( calculate_total_rent( master_list_filtered(read_csv(), 'Lease Years', '25')))) print(count_total_masts_by_tenant(read_csv())) print( tenant_data_between_dates(read_csv(), '01-Jun-1999', '31-Aug-2007')) elif user_input == '2': second_user_input() else: print('Sorry, your selection is not valid, please try again.\n') first_user_input()