tests: extend AVL and change parameters of WAVL
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
f67468b637
commit
f05aa87f4b
2 changed files with 33 additions and 5 deletions
36
test_avl.py
36
test_avl.py
|
@ -1,14 +1,42 @@
|
||||||
from avl import AVLTree
|
from avl import AVLTree, _balance_factor
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import random
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import hypothesis
|
import hypothesis
|
||||||
import hypothesis.strategies as st
|
import hypothesis.strategies as st
|
||||||
import logging
|
|
||||||
import pytest
|
import pytest
|
||||||
import random
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("values", "expected_balance_factor"),
|
||||||
|
[
|
||||||
|
([], 0),
|
||||||
|
([1], 0),
|
||||||
|
([1, -1], -1),
|
||||||
|
([1, 2], 1),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_balance_factor(
|
||||||
|
values: List[int], expected_balance_factor: int
|
||||||
|
) -> None:
|
||||||
|
tree = AVLTree()
|
||||||
|
for v in values:
|
||||||
|
tree.insert(v)
|
||||||
|
|
||||||
|
assert _balance_factor(tree.root) == expected_balance_factor
|
||||||
|
|
||||||
|
|
||||||
|
def test_incorrect_avl() -> None:
|
||||||
|
tree = AVLTree()
|
||||||
|
tree.insert(0)
|
||||||
|
tree.root.rank = 1
|
||||||
|
assert not tree.is_correct
|
||||||
|
|
||||||
|
|
||||||
def test_empty() -> None:
|
def test_empty() -> None:
|
||||||
tree = AVLTree()
|
tree = AVLTree()
|
||||||
|
|
||||||
|
@ -113,7 +141,7 @@ def _report(t_before: str, t_after: str) -> None:
|
||||||
print(t_after, file=after)
|
print(t_after, file=after)
|
||||||
|
|
||||||
|
|
||||||
@hypothesis.settings(max_examples=100000, deadline=None)
|
@hypothesis.settings(max_examples=1000, deadline=None)
|
||||||
@hypothesis.given(config=delete_strategy())
|
@hypothesis.given(config=delete_strategy())
|
||||||
def test_delete_random(config):
|
def test_delete_random(config):
|
||||||
values, delete_order = config
|
values, delete_order = config
|
||||||
|
|
|
@ -88,7 +88,7 @@ def test_rotate(values):
|
||||||
assert tree.is_correct
|
assert tree.is_correct
|
||||||
|
|
||||||
|
|
||||||
@hypothesis.settings(max_examples=1000, deadline=None)
|
@hypothesis.settings(max_examples=10000, deadline=None)
|
||||||
@hypothesis.given(values=st.sets(st.integers()))
|
@hypothesis.given(values=st.sets(st.integers()))
|
||||||
def test_insert_random(values):
|
def test_insert_random(values):
|
||||||
tree = WAVLTree()
|
tree = WAVLTree()
|
||||||
|
|
Loading…
Reference in a new issue