diff --git a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_Topology_test.res b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_Topology_test.res index fa96a15b..2399c808 100644 --- a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_Topology_test.res +++ b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_Topology_test.res @@ -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"] + }) }) diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_Topology.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_Topology.res index 0a955998..5c83cfc7 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_Topology.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_Topology.res @@ -81,16 +81,25 @@ let runOrderDiff = (current: array, previous0: array): array { 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