fix: invert logic
This commit is contained in:
@@ -21,28 +21,30 @@ class UpdateValidator
|
||||
Graph[rule.X].Add(rule.Y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// NOTE: This is basically a bubble sort
|
||||
//
|
||||
public Update Sort(Update update)
|
||||
{
|
||||
var sortedUpdate = new Update(update.Pages.ToList());
|
||||
|
||||
|
||||
while (Validate(sortedUpdate) is false)
|
||||
{
|
||||
for (var i = 0; i < sortedUpdate.Pages.Count - 1; i++)
|
||||
{
|
||||
var currentPage = sortedUpdate.Pages[i];
|
||||
var nextPage = sortedUpdate.Pages[i + 1];
|
||||
|
||||
if (IsOutOfOrder(currentPage, nextPage) is false)
|
||||
|
||||
if (IsInOrder(currentPage, nextPage))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
sortedUpdate.Pages[i] = nextPage;
|
||||
sortedUpdate.Pages[i + 1] = currentPage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return sortedUpdate;
|
||||
}
|
||||
|
||||
@@ -52,7 +54,7 @@ class UpdateValidator
|
||||
|
||||
foreach (var page in update.Pages)
|
||||
{
|
||||
if (previousPages.Any(previousPage => IsOutOfOrder(previousPage, page)))
|
||||
if (previousPages.Any(previousPage => IsInOrder(previousPage, page) is false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -63,9 +65,9 @@ class UpdateValidator
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsOutOfOrder(int previousPage, int futurePage)
|
||||
private bool IsInOrder(int previousPage, int futurePage)
|
||||
{
|
||||
return Graph.TryGetValue(previousPage, out var dependents) &&
|
||||
dependents.Contains(futurePage) is false;
|
||||
dependents.Contains(futurePage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user