def test_index(): """ index() should index the Bray-Curtis distances between terms. """ t = Text('aa bb cc') m = Matrix() m.index(t) assert m.get_pair('aa', 'bb') == t.score_braycurtis('aa', 'bb') assert m.get_pair('aa', 'cc') == t.score_braycurtis('aa', 'cc') assert m.get_pair('bb', 'cc') == t.score_braycurtis('bb', 'cc')
def test_index(): """ index() should index the Bray-Curtis distances between terms. """ t = Text('aa bb cc') m = Matrix() m.index(t) assert m.get_pair('aa', 'bb') == t.score_braycurtis('aa', 'bb') assert m.get_pair('aa', 'cc') == t.score_braycurtis('aa', 'cc') assert m.get_pair('bb', 'cc') == t.score_braycurtis('bb', 'cc')
def test_term_subset(): """ When a subset of terms is passed, just those terms should be indexed. """ t = Text('aa bb cc') m = Matrix() m.index(t, ['aa', 'bb']) # Should index 'aa' and 'bb'. assert m.get_pair('aa', 'bb') == t.score_braycurtis('aa', 'bb') # Should ignore 'cc'. assert not m.get_pair('aa', 'cc') assert not m.get_pair('bb', 'cc')
def test_term_subset(): """ When a subset of terms is passed, just those terms should be indexed. """ t = Text('aa bb cc') m = Matrix() m.index(t, ['aa', 'bb']) # Should index 'aa' and 'bb'. assert m.get_pair('aa', 'bb') == t.score_braycurtis('aa', 'bb') # Should ignore 'cc'. assert not m.get_pair('aa', 'cc') assert not m.get_pair('bb', 'cc')
def test_missing_key(): """ If an unindexed key pair is passed, return None. """ m = Matrix() m.set_pair('a', 'b', 1) assert m.get_pair('a', 'c') == None
def test_set_pair(): """ set_pair() should set the value under an order-independent key. """ m = Matrix() m.set_pair('a', 'b', 1) assert m.get_pair('a', 'b') == 1 assert m.get_pair('b', 'a') == 1