-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:dib-lab/sourmash into refactor/mi…
…nhash
- Loading branch information
Showing
10 changed files
with
202 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Hypothesis tests | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Set up Python 3.7 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: "3.7" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install -e .[test] | ||
- name: Run Hypothesis tests | ||
run: | | ||
python -m pytest --run-hypothesis --hypothesis-show-statistics --hypothesis-profile ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pytest | ||
|
||
from hypothesis import given, example | ||
import hypothesis.strategies as st | ||
|
||
from sourmash import MinHash | ||
from sourmash._minhash import get_max_hash_for_scaled | ||
|
||
|
||
@given(st.lists(st.integers(min_value=0, max_value=2**64 - 1), min_size=10, max_size=1000), | ||
st.lists(st.integers(min_value=0, max_value=2**64 - 1), min_size=10, max_size=1000), | ||
st.integers(min_value=10, max_value=1000)) | ||
@example([1, 2], [3, 4], 2) | ||
def test_set_abundance_num_hypothesis(hashes, abundances, sketch_size): | ||
a = MinHash(sketch_size, 10, track_abundance=True) | ||
oracle = dict(zip(hashes, abundances)) | ||
|
||
a.set_abundances(oracle) | ||
|
||
mins = a.get_mins(with_abundance=True) | ||
size = min(sum(1 for v in oracle.values() if v > 0), sketch_size) | ||
assert len(mins) == size | ||
|
||
for k, v in mins.items(): | ||
assert oracle[k] == v | ||
|
||
|
||
@given(st.lists(st.integers(min_value=0, max_value=2**64 - 1), min_size=10, max_size=1000), | ||
st.lists(st.integers(min_value=0, max_value=2**64 - 1), min_size=10, max_size=1000), | ||
st.integers(min_value=1000, max_value=10000)) | ||
@example([0], [0], 1000) | ||
def test_set_abundance_scaled_hypothesis(hashes, abundances, scaled): | ||
a = MinHash(0, 10, track_abundance=True, scaled=scaled) | ||
oracle = dict(zip(hashes, abundances)) | ||
|
||
a.set_abundances(oracle) | ||
|
||
max_hash = get_max_hash_for_scaled(scaled) | ||
below_max_hash = sum(1 for (k, v) in oracle.items() if k <= max_hash and v > 0) | ||
|
||
mins = a.get_mins(with_abundance=True) | ||
assert len(mins) == below_max_hash | ||
|
||
for k, v in mins.items(): | ||
assert oracle[k] == v | ||
assert k <= max_hash | ||
assert v > 0 |