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')]
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'}])
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()
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
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)
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)
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)
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')
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']]}