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 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 seq_empty_correct(): table = Table("table.txt") try: table.set_type("configuration") if table.sequential_search(FLAG_FIRST) == None: return "0.5" 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 remove_checks_empty(): table = Table("table.txt") try: table.set_type("configuration") except: return "0" try: table.remove_current_row() except: return "0.5" return "0"
def lod_checks_type(): table = Table("table.txt") try: table.set_type("configuration") except: return "0" try: table.load_one_document("poem.txt", "101") except: return "0.5" return "0"
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 lod_copies(): table = Table("table.txt") try: table.set_type("inverted_index") table.load_one_document("poem.txt", "100") copy_contents = open("docs/100", "r").read() original_contents = open("poem.txt", "r").read() if copy_contents == original_contents: return "0.5" except: return "0" return "0"
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 lod_works_multiple(): table = Table("table.txt") try: table.set_type("inverted_index") table.load_one_document("poem.txt", "104") table.load_one_document("blurb.txt", "105") last = table.sequential_search(FLAG_LAST) if last != ["uphill", ["105"]] and last != ["uphill", "105"]: return "0" second_last = table.sequential_search(FLAG_PREV) if second_last != ["quickly", ["104", "105"]] and second_last != ["quickly", "104,105"]: return "0" except: return "0" return "0.5"
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 set_key_checks_conflict(): table = Table("table.txt") try: table.set_type("configuration") table.set_key("degree") return "0" except: a = 0 table = Table("table.txt") try: table.set_type("inverted_index") table.set_key("key") return "0" except: a = 0 return "1"
def set_attributes_checks_conflict(): table = Table("table.txt") try: table.set_type("configuration") table.set_attributes(["name", "age"]) return "0" except: a = 0 table = Table("table.txt") try: table.set_type("inverted_index") table.set_attributes(["name", "age"]) return "0" except: a = 0 return "1"
def lod_works_correctly(): table = Table("table.txt") try: table.set_type("inverted_index") table.load_one_document("poem.txt", "103") first = table.sequential_search(FLAG_FIRST) if first != ["1", ["103"]] and first != ["1", "103"]: return "0" second = table.sequential_search(FLAG_NEXT) if second != ["2", ["103"]] and second != ["2", "103"]: return "0" last = table.sequential_search(FLAG_LAST) if last != ["quickly", ["103"]] and last != ["quickly", "103"]: return "0" except: return "0" return "3"
def set_type_attributes_correct(): table = Table("table.txt") score = 0 try: table.set_type("configuration") if table.get_attributes() == CONFIGURATION_ATTRIBUTES and table.get_degree() == 3 and table.get_key() == CONFIGURATION_KEY: score+=1 except: a = 0 table = Table("table.txt") try: table.set_type("inverted_index") if table.get_attributes() == INVERTED_INDEX_ATTRIBUTES and table.get_degree() == 2 and table.get_key() == INVERTED_INDEX_KEY: score+=1 except: a = 0 return str(score)
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 test_table_getters_and_setters(): table = Table("example_name.dat") if table.get_type() != "data": print("Default Table type must be data.") try: table.get_attributes() except: a = 0 # This code does nothing, but is necessary for the except block else: print("get_attributes() must raise an exception when no attributes are set.") table.set_attributes(["col1", "col2", "col3"]) if table.get_attributes() != ["col1", "col2", "col3"]: print("Attributes not set correctly.") table.set_key("col1") if table.get_key() != "col1": print("Key not set correctly.") try: table.set_key("non_existant_attribute") except: a = 0 # This code does nothing, but is necessary for the except block else: print("set_key() must raise an exception when key is not an attribute.") table.set_type("configuration") if table.get_attributes() != ["table_name", "degree", "list_of_attributes"]: print("Attributes not set correctly for 'configuration' type.") try: table.set_attributes(["incorrect_col1", "incorrect_col2", "incorrect_col3"]) except: a = 0 # This code does nothing, but is necessary for the except block else: print("set_attributes() must raise an exception when wrong attributes are set for 'configuration' type.")