Skip to content

Commit

Permalink
Distance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
travisjungroth committed Dec 19, 2022
1 parent 065a2ef commit c1ee700
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
34 changes: 34 additions & 0 deletions tests_distance.py
Original file line number Diff line number Diff line change
@@ -0,0 1,34 @@
from itertools import repeat

from hypothesis import strategies as st, given

from mtree4 import default_distance


def elements(n):
def g(f):
strats = [st.integers(), st.text()]
return given(st.one_of(*[st.tuples(*repeat(s, n)) for s in strats]))(f)
return g


@elements(3)
def test_triangle(items):
a, b, x = items
assert default_distance(a, b) <= default_distance(a, x) default_distance(x, b)


@elements(2)
def test_commutative(items):
a, b = items
assert default_distance(a, b) == default_distance(b, a)


@elements(2)
def test_positivity(items):
a, b = items
dist = default_distance(a, b)
if a == b:
assert dist == 0
else:
assert dist > 0
19 changes: 0 additions & 19 deletions tests_prop.py
Original file line number Diff line number Diff line change
@@ -1,8 1,6 @@
from itertools import chain
from typing import Any, Iterable

from hypothesis import given, strategies as st
from pytest import mark

from mtree4 import MTree, Node, ParentNode

Expand All @@ -18,23 16,6 @@ def get_nodes(node: Any, klass=Node) -> Iterable[ParentNode]:
yield from get_nodes(child, klass)


# def get_nodes_leaves_and_routers(tree: MTree) -> tuple[set[Node], set[LeafNode], set[RouterNode]]:
# leaf_nodes, router_nodes = set(), set()
# nodes = set(get_nodes(tree))
# for node in nodes:
# if isinstance(node, LeafNode):
# leaf_nodes.add(node)
# else:
# router_nodes.add(node)
# return nodes, leaf_nodes, router_nodes


# def get_parents(node: ParentNode) -> Iterable[RouterNode]:
# if node.parent is not None:
# yield node.parent
# yield from get_parents(node.parent)


values_strategy = st.sets(st.integers(min_value=0)) | st.sets(st.text())


Expand Down

0 comments on commit c1ee700

Please sign in to comment.