Example #1
0
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"
Example #2
0
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"
Example #3
0
def get_set_file_correct():
    table = Table("table.txt")
    try:
        table.set_file_name("file_name.dat")
        if table.get_file_name() == "file_name.dat":
            return "1"
    except:
        return "0"
    return "0"
Example #4
0
def set_attributes_correct():
    table = Table("table.txt")
    try:
        table.set_attributes(["name", "age", "weight"])
        if table.get_attributes() == ["name", "age", "weight"] and table.get_degree() == 3 and table.get_key() == "name":
            return "2"
    except:
        return "0"
    return "0"
Example #5
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"
Example #6
0
def pop_init_checks_format():
    table = Table("table.txt")
    try:
        table.set_attributes(["name", "age", "weight"])
    except:
        return "0"
    try:
        table.populate_initial_data("person_data_four_col.txt", "++++", "\n")
    except:
        return "0.5"
    return "0"
Example #7
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"
Example #8
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"
Example #9
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"
Example #10
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"
Example #11
0
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"   
Example #12
0
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" 
Example #13
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"
Example #14
0
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)  
Example #15
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"
Example #16
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"
Example #17
0
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"
Example #18
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"
Example #19
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"
Example #20
0
def seq_first_last_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])
        if table.sequential_search(FLAG_FIRST) != people_list[0]:
            return "0"
        if table.sequential_search(FLAG_LAST) != people_list[3]:
            return "0"     
    except:
        return "0"
    return "0.5" 
Example #21
0
def pop_init_correct():
    table = Table("table.txt")
    try:
        table.set_attributes(["name", "age", "weight", "children"])
        table.populate_initial_data("person_data_four_col.txt", "++++", "\n")
        if table.sequential_search(FLAG_FIRST) != ["Abe Simons", "48", "176", "3"]:
            return "0"
        if table.sequential_search(FLAG_LAST) != ["Lenny Peterson", "19", "201", "0"]:
            return "0"
    except:
        return "0"
    return "3"
Example #22
0
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"
Example #23
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"
Example #24
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"
Example #25
0
def set_key_correct():
    table = Table("table.txt")
    try:
        table.set_attributes(["first", "last", "id"])
        table.set_key("id")
        if table.get_key() == "id":
            return "1"
    except:
        return "0"
    return "0"
Example #26
0
def getters_raise_exceptions():
    table = Table("table.txt")
    try:
        table.get_degree()
        return "0"
    except:
        a = 0
    try:
        table.get_attributes()
        return "0"
    except:
        a = 0
    try:
        table.get_key()
        return "0"
    except:
        a = 0
    return "1"
Example #27
0
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.")
Example #28
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.")
Example #29
0
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.") 
Example #30
0
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"