refactoring and improvement, sort_env_files_by_rule now passes more complex test case

This commit is contained in:
Daniel 2023-12-04 14:38:09 +01:00
parent 2e988c6150
commit dc50a9d6f7

View file

@ -36,17 +36,13 @@ def is_rule_satisfied(in_list: list[EnvFile], rule: DependencyRule, swap=False)
child_indices = _get_indices_with_string(in_list, rule.child) child_indices = _get_indices_with_string(in_list, rule.child)
parent_indices = _get_indices_with_string(in_list, rule.dependency) parent_indices = _get_indices_with_string(in_list, rule.dependency)
child_index = min(child_indices)
results: list[bool] = []
for child_index in child_indices: for child_index in child_indices:
for parent_index in parent_indices: for parent_index in parent_indices:
if parent_index < child_index: if not parent_index < child_index:
results.append(True)
else:
if swap: if swap:
_swap_item_with_previous(in_list, parent_index) _swap_item_with_previous(in_list, parent_index)
results.append(False) return False
return all(results) return True
def sort_env_files_by_rule(env_list: list[EnvFile], rules: list[DependencyRule]) -> list[EnvFile]: def sort_env_files_by_rule(env_list: list[EnvFile], rules: list[DependencyRule]) -> list[EnvFile]: