Skip to content

Commit

Permalink
udpate counts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Dec 3, 2024
1 parent 7486184 commit 2405648
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 deletions lisc/tests/collect/test_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def test_collect_counts_two(test_req):

terms_a = ['language', 'memory']
excls_a = [['protein'], ['protein']]
excls_a = [['protein'], ['cell']]
terms_b = ['brain']

# Test co-occurence with two terms lists
Expand All @@ -22,7 +22,7 @@ def test_collect_counts_two(test_req):
def test_collect_counts_one(test_req):

terms_a = ['language', 'memory']
excls_a = [['protein'], ['protein']]
excls_a = [['protein'], ['cell']]

# Test co-occurence with one list of terms
cooc, counts, meta_data = collect_counts(\
Expand All @@ -34,7 +34,7 @@ def test_collect_counts_one(test_req):
def test_collect_counts_nocooc(test_req):

terms_a = ['language', 'memory']
excls_a = [['protein'], ['protein']]
excls_a = [['protein'], ['cell']]

# Test coounts without co-occurence
counts, meta_data = collect_counts(\
Expand Down
56 changes: 29 additions & 27 deletions lisc/tests/objects/test_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,40 @@
###################################################################################################
###################################################################################################

## Helper test functions
## Helper test functions for Counts object

def check_dunders(counts):

if isinstance(counts, Counts1D):
label0 = counts.terms['A'].labels[0]
label1 = counts.terms['B' if counts.terms['B'].terms else 'A'].labels[0]

label = counts.labels[0]
out = counts[label0]

assert out == counts.counts[0]

if isinstance(counts, Counts):

label0 = counts.terms['A'].labels[0]
label1 = counts.terms['B' if counts.terms['B'].terms else 'A'].labels[0]

out = counts[label0, label1]
assert out == counts.counts[(0, 0)]
out = counts[label0, label1]
assert out == counts.counts[(0, 0)]

def check_funcs(counts):

if isinstance(counts, Counts):
counts.check_data()
counts.check_top()
counts.check_counts()
for dim in ['A'] if counts.square else ['A', 'B', 'both']:
counts.check_data(dim=dim)
counts.check_top(dim=dim)
counts.check_counts(dim=dim)

def drop_data(counts):

counts.drop_data(0)
for dim in ['A'] if counts.square else ['A', 'B', 'both']:
counts.drop_data(10, dim=dim)

def compute_scores(counts):

for score_type in ['normalize', 'association', 'similarity']:
counts.compute_score(score_type)
assert counts.score.any()
assert counts.score_info['type'] == score_type
counts.compute_score('association')
assert counts.score.any()
assert counts.score_info['type'] == 'association'

for score_type in ['similarity', 'normalize']:
for dim in ['A'] if counts.square else ['A', 'B']:
counts.compute_score(score_type, dim=dim)
assert counts.score.any()
assert counts.score_info['type'] == score_type
assert counts.score_info['dim'] == dim

## Counts1D Object

Expand All @@ -57,8 +55,12 @@ def test_collect(test_req):

assert counts.has_data

check_funcs(counts)
drop_data(counts)
assert counts[counts.labels[0]] == counts.counts[0]

counts.check_top()
counts.check_counts()

counts.drop_data(10)

## Counts Object

Expand All @@ -78,7 +80,7 @@ def test_collect_one(test_req):
counts = Counts()

counts.add_terms(['language', 'memory'], dim='A')
counts.add_terms(['protein', 'protein'], term_type='exclusions', dim='A')
counts.add_terms(['protein', 'cell'], term_type='exclusions', dim='A')

counts.run_collection(db='pubmed', logging=test_req)
assert counts.has_data
Expand All @@ -94,7 +96,7 @@ def test_collect_two(test_req):
counts = Counts()

counts.add_terms(['language', 'memory'], dim='A')
counts.add_terms(['protein', 'protein'], term_type='exclusions', dim='A')
counts.add_terms(['protein', 'cell'], term_type='exclusions', dim='A')
counts.add_terms(['cognition'], dim='B')

counts.run_collection(db='pubmed', logging=test_req)
Expand Down

0 comments on commit 2405648

Please sign in to comment.