def test_table_file_operations(): table = Table("person_data.dat") table.set_attributes(["name", "age", "weight"]) table.set_key("name") try: table.populate_initial_data("person_data_four_col.txt", "++++", "\n") except: a = 0 # This code does nothing, but is necessary for the except block else: print("populate_initial_data() must raise an exception when input file has incorrect format.") table.populate_initial_data("person_data_three_col.txt", "++++", "\n") if table.get_size() != 12: print(table.get_size()) print("Table size not correct after populating initial data.") if table.sequential_search("first") != ["Abe Simons", "48", "176"]: print("First row of Table after populating initial data is incorrect.") if table.sequential_search("last") != ["Jules Rory", "25", "167"]: print("Last row of Table after populating initial data is incorrect.") table = Table("inverted_index_table.dat") table.set_type("inverted_index") table.load_one_document("story.txt", "101") if table.get_size() != 347: print(table.get_size()) print("Table size incorrect after loading one document.") if table.sequential_search("first") != ["the", "101"]: print("First row of Table is incorrect after loading one document.") if table.key_search("darigan") != ["darigan", "101"]: print("Table is missing key(s) after loading one document.")
def defaults_correct(): table = Table("file_name.dat") try: if table.get_type() == "data" and table.get_size() == 0 and table.get_file_name() == "file_name.dat": return "1" except: return "0" return "0"
def lod_sets_size(): table = Table("table.txt") try: table.set_type("inverted_index") table.load_one_document("poem.txt", "102") if table.get_size() == 13: return "0.5" except: return "0" return "0"
def pop_init_updates_size(): table = Table("table.txt") try: table.set_attributes(["name", "age", "weight"]) table.populate_initial_data("person_data_three_col.txt", "++++", "--::--") if table.get_size() == 6: 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 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 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"