def seq_next_prev_correct(): table = Table("table.txt") people_list = [["Amy", "23"], ["Bridgette", "32"], ["Dave", "26"], ["Joe", "44"]] try: table.set_attributes(["name", "age"]) table.append(people_list[0]) table.append(people_list[1]) table.append(people_list[2]) table.append(people_list[3]) table.sequential_search(FLAG_FIRST) if table.sequential_search(FLAG_NEXT) != people_list[1]: return "0" if table.sequential_search(FLAG_NEXT) != people_list[2]: return "0" if table.sequential_search(FLAG_NEXT) != people_list[3]: return "0" if table.sequential_search(FLAG_PREV) != people_list[2]: return "0" if table.sequential_search(FLAG_PREV) != people_list[1]: return "0" if table.sequential_search(FLAG_PREV) != people_list[0]: return "0" except: return "0" return "0.5"
def save_load_correct(): table = Table("data_table4.dat") people_list = [["Amy", "23", "121"], ["Bridgette", "32", "144"], ["Dave", "26", "153"], ["Joe", "44", "176"]] try: table.set_attributes(["name", "age", "weight"]) table.append(people_list[0]) table.append(people_list[1]) table.append(people_list[2]) table.append(people_list[3]) table.save() except: return "0" table = Table("data_table4.dat") try: table.set_attributes(["name", "age", "weight"]) table.load() if table.sequential_search(FLAG_FIRST) != people_list[0]: return "0" if table.sequential_search(FLAG_NEXT) != people_list[1]: return "0" if table.sequential_search(FLAG_LAST) != people_list[3]: return "0" except: return "0" return "4"
def set_something_checks_size(): table = Table("table.txt") try: table.set_attributes(["name", "age"]) table.append(["Joe", "41"]) except: return "0" try: table.set_type("configuration") return "0" except: a = 0 try: table.set_key("name") return "0" except: a = 0 try: table.set_attributes(["name", "age", "weight"]) return "0" except: a = 0 try: table.set_file_name("file_name.dat") return "0" except: a = 0 return "1"
def seq_points_first(): table = Table("table.txt") try: table.set_type("configuration") table.append(["cars", 3, ["make", "year", "color"]]) table.append(["people", 2, ["name", "age"]]) if table.sequential_search(FLAG_NEXT) == ["people", 2, ["name", "age"]]: return "0.5" except: return "0" return "0"
def append_checks_length(): table = Table("table.txt") try: table.set_type("configuration") except: return "0" try: table.append(["people", 5]) except: return "0.5" return "0"
def append_updates_size(): table = Table("table.txt") try: table.set_attributes(["name", "age"]) table.append(["Joe", 47]) table.append(["Sarah", 23]) if table.get_size() == 2: return "0.5" except: return "0" return "0"
def key_search_pointer_update(): table = Table("table.txt") car_list = [["Focus", "Ford"], ["Mustang", "Ford"], ["Rio", "Chevy"]] try: table.set_attributes(["model", "manufacturer"]) table.append(car_list[0]) table.append(car_list[1]) table.append(car_list[2]) table.key_search("Mustang") if table.sequential_search(FLAG_NEXT) == car_list[2]: return "0.5" except: return "0" return "0"
def key_search_found(): table = Table("table.txt") table_list = [["cars", 3, ["make", "year", "color"]], ["people", 2, ["name", "age"]], ["students", 4, ["id", "first", "last", "year"]]] try: table.set_type("configuration") table.append(table_list[0]) table.append(table_list[1]) table.append(table_list[2]) if table.key_search("cars") != table_list[0]: return "0" if table.key_search("students") != table_list[2]: return "0" except: return "0" return "0.5"
def key_search_not_found(): table = Table("table.txt") car_list = [["Focus", "Ford"], ["Mustang", "Ford"], ["Rio", "Chevy"]] try: table.set_attributes(["model", "manufacturer"]) table.append(car_list[0]) table.append(car_list[1]) table.append(car_list[2]) if table.key_search("Camaro") != None: return "0" if table.key_search("Ford") != None: return "0" except: return "0" return "0.5"
def load_checks_format(): table = Table("data_table2.dat") try: table.set_attributes(["name", "age"]) table.append(["Joe", "19"]) table.save() except: return "0" table = Table("data_table2.dat") try: table.set_attributes(["name", "age", "weight"]) except: return "0" try: table.load() except: return "0.5" return "0"
def load_overwrites(): table = Table("data_table3.dat") try: table.set_attributes(["name", "age"]) table.append(["Joe", "19"]) table.save() except: return "0" table = Table("data_table3.dat") try: table.set_attributes(["name", "age"]) table.append(["Alice", "33"]) table.append(["Frank", "48"]) table.load() if table.get_size() == 1: return "0.5" except: return "0" return "0"
def remove_updates_size(): table = Table("table.txt") table_list = [["cars", 3, ["make", "year", "color"]], ["people", 2, ["name", "age"]], ["students", 4, ["id", "first", "last", "year"]]] try: table.set_type("configuration") table.append(table_list[0]) table.append(table_list[1]) table.append(table_list[2]) table.sequential_search(FLAG_FIRST) table.remove_current_row() if table.get_size() != 2: return "0" table.sequential_search(FLAG_FIRST) table.remove_current_row() if table.get_size() != 1: return "0" except: return "0" return "0.5"
def remove_sets_none(): table = Table("table.txt") car_list = [["Focus", "Ford"], ["Mustang", "Ford"], ["Rio", "Chevy"]] try: table.set_attributes(["model", "manufacturer"]) table.append(car_list[0]) table.append(car_list[1]) table.append(car_list[2]) except: return "0" try: table.remove_current_row() table.remove_current_row() table.remove_current_row() if table.sequential_search(FLAG_FIRST) == None: return "0.5" except: return "0" return "0"
def remove_updates_pointer(): table = Table("table.txt") people_list = [["Amy", "23"], ["Bridgette", "32"], ["Dave", "26"], ["Joe", "44"]] try: table.set_attributes(["name", "age"]) table.append(people_list[0]) table.append(people_list[1]) table.append(people_list[2]) table.append(people_list[3]) table.sequential_search(FLAG_FIRST) table.sequential_search(FLAG_NEXT) table.remove_current_row() if table.sequential_search(FLAG_NEXT) != people_list[3]: return "0" table.remove_current_row() if table.sequential_search(FLAG_NEXT) != people_list[2]: return "0" except: return "0" return "0.5"
def append_checks_keys(): table = Table("table.txt") try: table.set_type("configuration") table.append(["people", 2, ["name", "age"]]) table.append(["cars", 3, ["make", "year", "color"]]) except: return "0" try: table.append(["people", 4, ["name", "age", "weight", "height"]]) except: return "0.5" return "0"
def test_table_data_and_search(): table = Table("data_table.dat") table.set_attributes(["name", "age", "weight"]) table.set_key("name") table.append(["Abe Simons", "48", "176"]) table.append(["Billy Kidd", "17", "145"]) table.append(["Emily Smith", "22", "138"]) table.append(["Carla Cree", "34", "215"]) table.append(["David Johnson", "71", "165"]) table.append(["Katherine Diaz", "32", "144"]) table.append(["Frank Small", "29", "129"]) table.append(["George Sorenson", "16", "188"]) table.append(["Lenny Peterson", "19", "201"]) table.append(["Heidi Thomson", "55", "133"]) table.append(["Iggy Bat", "61", "153"]) table.append(["Jules Rory", "25", "167"]) sequential_search_correct = True if table.sequential_search("first") != ["Abe Simons", "48", "176"]: sequential_search_correct = False if table.sequential_search("last") != ["Jules Rory", "25", "167"]: sequential_search_correct = False if table.sequential_search("prev") != ["Iggy Bat", "61", "153"]: sequential_search_correct = False if table.sequential_search("next") != ["Jules Rory", "25", "167"]: sequential_search_correct = False if not sequential_search_correct: print("Sequential search does not work correctly.") if table.key_search("Nobody") != None: print("Key search must return None when key does not exist in Table.") if table.key_search("George Sorenson") != ["George Sorenson", "16", "188"]: print("Key search must return row when key does exist in Table.") if table.sequential_search("prev") != ["Frank Small", "29", "129"]: print("Current pointer not set correctly after key search.")