2022-02-03 11:35:12 +01:00
|
|
|
from avl import AVLTree
|
|
|
|
from wavl import WAVLTree
|
|
|
|
from comparator import Comparator
|
2022-05-18 13:39:54 +02:00
|
|
|
from test_properties import delete_strategy
|
2022-02-03 11:35:12 +01:00
|
|
|
|
|
|
|
import hypothesis
|
2022-05-07 15:40:10 +02:00
|
|
|
import pytest
|
2022-02-03 11:35:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def report_different(before, deleted, comparator):
|
|
|
|
h = abs(hash(before))
|
|
|
|
with (
|
|
|
|
open(f"trees/{h}_before.dot", "w") as b,
|
|
|
|
open(f"trees/{h}_d{deleted}_after.dot", "w") as a,
|
|
|
|
):
|
|
|
|
print(before, file=b)
|
|
|
|
print(comparator, file=a)
|
|
|
|
|
|
|
|
|
2022-05-07 15:40:10 +02:00
|
|
|
@pytest.mark.xfail
|
2022-02-03 11:35:12 +01:00
|
|
|
@hypothesis.settings(max_examples=10000, deadline=None)
|
|
|
|
@hypothesis.given(config=delete_strategy())
|
2022-05-07 15:40:10 +02:00
|
|
|
def test_delete_ranks_differ(config):
|
2022-02-03 11:35:12 +01:00
|
|
|
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_equal
|
|
|
|
except AssertionError:
|
|
|
|
report_different(before, value, comparator)
|
|
|
|
raise
|
2022-05-07 15:40:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
@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
|