diff --git a/test_avl.py b/test_avl.py index 8b1970e..ba7388a 100644 --- a/test_avl.py +++ b/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.strategies as st -import logging import pytest -import random 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: tree = AVLTree() @@ -113,7 +141,7 @@ def _report(t_before: str, t_after: str) -> None: print(t_after, file=after) -@hypothesis.settings(max_examples=100000, deadline=None) +@hypothesis.settings(max_examples=1000, deadline=None) @hypothesis.given(config=delete_strategy()) def test_delete_random(config): values, delete_order = config diff --git a/test_wavl.py b/test_wavl.py index 5d182f5..76c19dc 100644 --- a/test_wavl.py +++ b/test_wavl.py @@ -88,7 +88,7 @@ def test_rotate(values): 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())) def test_insert_random(values): tree = WAVLTree()