Fix topology runOrderDiff
This commit is contained in:
parent
ac63b57478
commit
4e5e05530e
|
@ -6,11 +6,19 @@ open Expect
|
||||||
open Expect.Operators
|
open Expect.Operators
|
||||||
|
|
||||||
describe("Topology", () => {
|
describe("Topology", () => {
|
||||||
Only.test("when equal 1x", () => {
|
test("when equal 1x", () => {
|
||||||
Topology.runOrderDiff(["a"], ["a"])->expect == []
|
Topology.runOrderDiff(["a"], ["a"])->expect == []
|
||||||
})
|
})
|
||||||
|
|
||||||
test("when equal 3x", () => {
|
test("when equal 3x", () => {
|
||||||
Topology.runOrderDiff(["a", "b", "c"], ["a", "b", "c"])->expect == []
|
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"]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -81,16 +81,25 @@ let runOrderDiff = (current: array<string>, previous0: array<string>): array<str
|
||||||
Belt.Array.forEach(filler, _ => {
|
Belt.Array.forEach(filler, _ => {
|
||||||
let _ = Js.Array2.push(previous, "")
|
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)) => {
|
let (_, affected) = Belt.Array.reduce(zipped, (true, []), ((wasEqual, acc), (curr, prev)) => {
|
||||||
switch wasEqual {
|
switch wasEqual {
|
||||||
| true =>
|
| true =>
|
||||||
if curr == prev {
|
if curr == prev {
|
||||||
(true, Belt.Array.concat(acc, [curr]))
|
(true, acc)
|
||||||
} else {
|
} else {
|
||||||
(false, acc)
|
(false, Belt.Array.concat(acc, [curr]))
|
||||||
}
|
}
|
||||||
| false => (false, acc)
|
| false => (false, Belt.Array.concat(acc, [curr]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
affected
|
affected
|
||||||
|
|
Loading…
Reference in New Issue
Block a user