Fix topology runOrderDiff

This commit is contained in:
Umur Ozkul 2022-08-26 00:45:13 +02:00
parent ac63b57478
commit 4e5e05530e
2 changed files with 22 additions and 5 deletions

View File

@ -6,11 +6,19 @@ open Expect
open Expect.Operators
describe("Topology", () => {
Only.test("when equal 1x", () => {
test("when equal 1x", () => {
Topology.runOrderDiff(["a"], ["a"])->expect == []
})
test("when equal 3x", () => {
Topology.runOrderDiff(["a", "b", "c"], ["a", "b", "c"])->expect == []
})
test("less dependents", () => {
Topology.runOrderDiff(["a", "b"], ["a", "b", "c", "d"])->expect == []
})
test("more dependents", () => {
Topology.runOrderDiff(["a", "b", "c", "d"], ["a", "b"])->expect == ["c", "d"]
})
})

View File

@ -81,16 +81,25 @@ let runOrderDiff = (current: array<string>, previous0: array<string>): array<str
Belt.Array.forEach(filler, _ => {
let _ = Js.Array2.push(previous, "")
})
let zipped = Belt.Array.zip(current, previous)
let zipped: array<(string, string)> = Belt.Array.zip(current, previous)
// zipped
// ->Belt.Array.map(((curr, prev)) => {
// let result = `(${curr}, ${prev})`
// result
// })
// ->Js.Array2.joinWith(", ")
// ->Js.log
let (_, affected) = Belt.Array.reduce(zipped, (true, []), ((wasEqual, acc), (curr, prev)) => {
switch wasEqual {
| true =>
if curr == prev {
(true, Belt.Array.concat(acc, [curr]))
(true, acc)
} else {
(false, acc)
(false, Belt.Array.concat(acc, [curr]))
}
| false => (false, acc)
| false => (false, Belt.Array.concat(acc, [curr]))
}
})
affected