tests: generate AVL vs WAVL difference by contradiction

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-07 15:40:10 +02:00
parent f05aa87f4b
commit e50cca7a14
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -4,6 +4,7 @@ from comparator import Comparator
from test_wavl import delete_strategy from test_wavl import delete_strategy
import hypothesis import hypothesis
import pytest
def report_different(before, deleted, comparator): def report_different(before, deleted, comparator):
@ -16,9 +17,10 @@ def report_different(before, deleted, comparator):
print(comparator, file=a) print(comparator, file=a)
@pytest.mark.xfail
@hypothesis.settings(max_examples=10000, deadline=None) @hypothesis.settings(max_examples=10000, deadline=None)
@hypothesis.given(config=delete_strategy()) @hypothesis.given(config=delete_strategy())
def test_delete(config): def test_delete_ranks_differ(config):
values, order = config values, order = config
comparator = Comparator(AVLTree(), WAVLTree()) comparator = Comparator(AVLTree(), WAVLTree())
@ -35,3 +37,25 @@ def test_delete(config):
except AssertionError: except AssertionError:
report_different(before, value, comparator) report_different(before, value, comparator)
raise raise
@pytest.mark.xfail
@hypothesis.settings(max_examples=10000, deadline=None)
@hypothesis.given(config=delete_strategy())
def test_delete_trees_differ(config):
values, order = config
comparator = Comparator(AVLTree(), WAVLTree())
for value in values:
comparator.insert(value)
for value in order:
before = str(comparator.left)
comparator.delete(value)
try:
assert comparator.are_similar
except AssertionError:
report_different(before, value, comparator)
raise