Skip to content

Commit

Permalink
tests and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Jungroth committed Jun 16, 2023
1 parent c9bd854 commit 7ee9923
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion m_tree/__init__.py
Original file line number Diff line number Diff line change
@@ -1 0,0 @@
from m_tree.classes import MTree
19 changes: 16 additions & 3 deletions tests/helpers.py → tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 1,8 @@
import random

from hypothesis import given, strategies as st, assume
from hypothesis import given, strategies as st, settings

from m_tree import PriorityQueue, LimitedSet
from m_tree.helpers import PriorityQueue, LimitedSet


@given(...)
Expand All @@ -22,13 22,26 @@ def test_pq(value_to_priority: dict[float, int], pops: list[bool]):
contained.remove((p, v))


# rerun this test many times since it is probabilistic
@settings(max_examples=1000)
@given(value_to_priority=..., k=st.integers(min_value=1), pops=...)
def test_limited_set(value_to_priority: dict[int, int], k: int, pops: list[bool]):
limited_set = LimitedSet(k)
for item, p in value_to_priority.items():
before = limited_set.items.copy()
limited_set.add(p, item)
assert limited_set.items >= before
assert len(limited_set.items) <= k
if len(before) < k:
assert item in limited_set.items
assert limited_set.items == before | {item}
else:
dropped = (before | {item}) - limited_set.items
assert item in limited_set.items or item in dropped
if dropped:
dropped_item, = dropped
drop_pri = value_to_priority[dropped_item]
assert all(drop_pri >= value_to_priority[i] for i in limited_set.items)

if pops and pops.pop():
removal = random.choice(list(limited_set.items))
limited_set.discard(removal)
Expand Down
1 change: 0 additions & 1 deletion tests/test_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 73,6 @@ def test_sufficient_radius(values, cap):

class TestKnn:
@given(st.sets(vectors, min_size=1), vectors, st.integers(1))
@settings(max_examples=10000)
def test_correct(self, values, needle, k):
tree = MTree(values)
res = tree.knn(needle, k)
Expand Down

0 comments on commit 7ee9923

Please sign in to comment.