示例#1
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.")
示例#2
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"
示例#3
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"
示例#4
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"
示例#5
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"
示例#6
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"