add test script for dependency resolving algorithm
This commit is contained in:
parent
1eabe31e9e
commit
5541e7a88a
1 changed files with 40 additions and 0 deletions
40
tests/test_utils.py
Normal file
40
tests/test_utils.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from prototyping.sorting_algo import Rule, is_rule_satisfied, sort_by_rules
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def in_list():
|
||||||
|
return ["a", "b", "c", "d", "e", "f", "g"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def rules() -> list[Rule]:
|
||||||
|
return [ # X depends on Y
|
||||||
|
Rule("a", "e"),
|
||||||
|
Rule("b", "e"),
|
||||||
|
Rule("b", "f"),
|
||||||
|
Rule("c", "e"),
|
||||||
|
Rule("d", "e"),
|
||||||
|
Rule("f", "e"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def has_unique_elements(in_list):
|
||||||
|
return len(set(in_list)) == len(in_list)
|
||||||
|
|
||||||
|
|
||||||
|
def has_rules_satisfied(in_list, rules):
|
||||||
|
rule_satisfied: list[bool] = []
|
||||||
|
for rule in rules:
|
||||||
|
if is_rule_satisfied(in_list, rule):
|
||||||
|
rule_satisfied.append(True)
|
||||||
|
else:
|
||||||
|
rule_satisfied.append(False)
|
||||||
|
return all(rule_satisfied)
|
||||||
|
|
||||||
|
|
||||||
|
def test_stuff(in_list, rules):
|
||||||
|
sort_by_rules(in_list, rules)
|
||||||
|
assert has_unique_elements(in_list)
|
||||||
|
assert has_rules_satisfied(in_list, rules)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue