예제 #1
0
def test_find_trans_deps():
    dep_dic = {
        'A': [], 'B': [], 'C': [], 'D': [['F']],
        'E': [['A', 'B', 'C', 'D']], 'F': [['A', 'B']]}
    dep = Dependencies(dep_dic, ['A', 'B', 'C'])
    dep.remove_implied_extroneous()
    assert dep.find_trans_deps() == [(['F'], 'D')]
예제 #2
0
def test_find_candidate_keys():
    dep_dic = {
        'A': [['B']], 'B': [['E'], ['A', 'D']], 'C': [['E', 'F']],
        'D': [['A']], 'E': [['A']], 'F': [['G']], 'G': []}
    dependencies = Dependencies(dep_dic)
    dependencies.remove_implied_extroneous()
    assert_equal_cand_keys(dependencies.find_candidate_keys(), [{'A', 'G'}, {'B', 'G'}, {'E', 'G'}])
예제 #3
0
def test_from_rels():
    dep_dic = {
        'A': [['B']], 'B': [['E'], ['A', 'D']], 'C': [['E', 'F']],
        'D': [['A']], 'E': [['A']], 'F': [['G']], 'G': []}
    dependencies = Dependencies(dep_dic)
    rels = dependencies.tuple_relations()
    dependencies_new = Dependencies.from_rels(rels)
    assert dependencies.serialize() == dependencies_new.serialize()
예제 #4
0
def test_find_closure():
    dep_dic = {
        'A': [['B']], 'B': [['E'], ['A', 'D']], 'C': [['E', 'F']],
        'D': [['A']], 'E': [['A']], 'F': [['G']], 'G': []}
    dependencies = Dependencies(dep_dic)
    rels = dependencies.tuple_relations()
    clos = {'A', 'B', 'D', 'E'}
    assert find_closure(rels, ['A']) == clos
예제 #5
0
def test_find_partial_deps():
    dep_dic = {
        'A': [['B']], 'B': [['E'], ['A', 'D']], 'C': [['E', 'F']],
        'D': [['A']], 'E': [['A']], 'F': [['G']], 'G': []}
    dependencies = Dependencies(dep_dic, ['A', 'G'])
    dependencies.remove_implied_extroneous()
    partial_deps = [(['A'], 'D'), (['G'], 'F'), (['A'], 'B'), (['A'], 'E')]
    assert_equal_tuple_rels(dependencies.find_partial_deps(), partial_deps)
예제 #6
0
def test_tuple_relations():
    dep_dic = {'A': [], 'B': [['A']], 'C': [['D', 'G'], ['A']],
               'D': [['A'], ['C', 'G']], 'E': [['D', 'G'], ['A'], ['C']]}
    dependencies = Dependencies(dep_dic)
    tuple_comp = [(['D', 'G'], 'C'), (['A'], 'C'), (['A'], 'B'),
                  (['D', 'G'], 'E'), (['A'], 'E'), (['C'], 'E'),
                  (['A'], 'D'), (['C', 'G'], 'D')]
    assert_equal_tuple_rels(dependencies.tuple_relations(), tuple_comp)
예제 #7
0
def test_add_and_remove_dep():
    dep_dic = {'A': [], 'B': [['A']], 'C': [['D', 'G'], ['A']],
               'D': [['A'], ['C', 'G']], 'E': [['D', 'G'], ['A'], ['C']],
               'F': [['A'], ['B']], 'G': [['A'], ['C', 'D']]}
    dependencies = Dependencies(dep_dic)
    dependencies.add_dep('B', ['C'])
    assert_equal_dependency_dics(dependencies.serialize(),
                                 {'A': [], 'B': [['A'], ['C']], 'C': [['D', 'G'], ['A']],
                                  'D': [['A'], ['C', 'G']], 'E': [['D', 'G'], ['A'], ['C']],
                                  'F': [['A'], ['B']], 'G': [['A'], ['C', 'D']]})
    dependencies.remove_dep('B', ['C'])
    assert_equal_dependency_dics(dependencies.serialize(), dep_dic)
예제 #8
0
def test_equi_atttrs():
    dep_dic = {'A': [['B']], 'B': [['A']], 'C': [], 'D': [['A']]}
    dep = Dependencies(dep_dic, ['A', 'C'])
    assert dep.equiv_attrs('A', 'B')
    assert not dep.equiv_attrs('A', 'D')
예제 #9
0
def test_remove_implied_extroneous():
    dep_dic = {'A': [], 'B': [['A']], 'C': [['A', 'B']]}
    dependencies = Dependencies(dep_dic)
    dependencies.remove_implied_extroneous()
    assert dependencies.serialize() == {'A': [], 'B': [['A']], 'C': [['A']]}