Lanes: a few curves take the order that crosses least, of all orders

The unit test that failed about one run in six was the lanes property: moving
one curve at a time could stop at a local minimum (two crossings where an
order has none). Up to six curves in a gutter every order is now tried, a
strictly better one replacing the order there, so the bundle still keeps its
order while nothing crosses less. The property now asks for the least and
the counterexample it found is kept as a case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-16 02:02:41 -05:00
1 parent 1e0469477c
commit edc31aac9a
2 files changed
+27 -3

No files matched your search

+5 -1
View File
@@ -38,9 +38,13 @@ describe("lanes", () => {
const es = ys.map(([a, b], i) => e(String(i), a, b));
const o = laneOrder(es);
const again = laneOrder(es, keys(o));
return o.length === es.length && new Set(keys(o)).size === es.length && keys(again).join() === keys(o).join() && (es.length > 6 || crossings(o) <= least(es) + 1);
return o.length === es.length && new Set(keys(o)).size === es.length && keys(again).join() === keys(o).join() && (es.length > 6 || crossings(o) === least(es));
}),
{ numRuns: 300 },
);
// Found by the property above (it failed about one run in six): moving one curve at a time stopped at 2 crossings where an order has none.
const stuck = [e("0", 3, 1), e("1", 6, 2), e("2", 7, 4), e("3", 2, 0)];
expect(crossings(laneOrder(stuck))).toBe(0);
// A small scroll that changes no crossing keeps the lanes as they were.
const before = laneOrder([e("a", 300, 100), e("b", 335, 400), e("c", 370, 700)]);
const after = laneOrder([e("a", 290, 100), e("b", 325, 400), e("c", 360, 700)], keys(before));