Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m6s
New lib/erlang/lists-ext.sx (loaded after runtime.sx): stable merge sort over an SX-list bridge. sort/1 and usort/1 use full Erlang term order via a self-contained er-ext-lt? (deep tuple/list compare that the shared er-lt? lacks); sort/2 takes a fun(A,B)->bool comparator. Registration wraps er-register-builtin-bifs! so the BIFs survive the mid-run registry resets done by tests/runtime.sx. Roadmap is saturated within this loop's scope; this is forever-loop stdlib hardening. New file forced by the broken sx-tree write tools in this worktree (see Blockers) — authored via Write + sx_validate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
77 lines
2.9 KiB
Plaintext
77 lines
2.9 KiB
Plaintext
;; lists-ext tests — lists:sort/1, lists:sort/2, lists:usort/1.
|
|
;; Each case evaluates an Erlang expression that reduces to the bool
|
|
;; atom `true` (via =:= on the sorted result) and checks its name.
|
|
|
|
(define er-lx-test-count 0)
|
|
(define er-lx-test-pass 0)
|
|
(define er-lx-test-fails (list))
|
|
|
|
(define
|
|
er-lx-test
|
|
(fn
|
|
(name actual expected)
|
|
(set! er-lx-test-count (+ er-lx-test-count 1))
|
|
(if
|
|
(= actual expected)
|
|
(set! er-lx-test-pass (+ er-lx-test-pass 1))
|
|
(append! er-lx-test-fails {:name name :expected expected :actual actual}))))
|
|
|
|
;; eval an Erlang source string and return the result atom's name
|
|
(define er-lx-nm (fn (src) (get (erlang-eval-ast src) :name)))
|
|
|
|
;; ── lists:sort/1 ──────────────────────────────────────────────────
|
|
(er-lx-test "sort/1 ascending"
|
|
(er-lx-nm "lists:sort([3,1,2]) =:= [1,2,3]") "true")
|
|
|
|
(er-lx-test "sort/1 already sorted"
|
|
(er-lx-nm "lists:sort([1,2,3]) =:= [1,2,3]") "true")
|
|
|
|
(er-lx-test "sort/1 empty"
|
|
(er-lx-nm "lists:sort([]) =:= []") "true")
|
|
|
|
(er-lx-test "sort/1 singleton"
|
|
(er-lx-nm "lists:sort([7]) =:= [7]") "true")
|
|
|
|
(er-lx-test "sort/1 keeps duplicates"
|
|
(er-lx-nm "lists:sort([3,1,2,1]) =:= [1,1,2,3]") "true")
|
|
|
|
(er-lx-test "sort/1 length preserved"
|
|
(erlang-eval-ast "length(lists:sort([5,4,3,2,1]))") 5)
|
|
|
|
(er-lx-test "sort/1 term order: number < atom"
|
|
(er-lx-nm "lists:sort([b,a,1]) =:= [1,a,b]") "true")
|
|
|
|
(er-lx-test "sort/1 tuples elementwise"
|
|
(er-lx-nm "lists:sort([{2,a},{1,b},{1,a}]) =:= [{1,a},{1,b},{2,a}]") "true")
|
|
|
|
;; ── lists:sort/2 ──────────────────────────────────────────────────
|
|
(er-lx-test "sort/2 ascending =<"
|
|
(er-lx-nm "lists:sort(fun(A,B) -> A =< B end, [3,1,2]) =:= [1,2,3]") "true")
|
|
|
|
(er-lx-test "sort/2 descending >="
|
|
(er-lx-nm "lists:sort(fun(A,B) -> A >= B end, [1,3,2]) =:= [3,2,1]") "true")
|
|
|
|
(er-lx-test "sort/2 stable on equal keys"
|
|
(er-lx-nm
|
|
"lists:sort(fun({A,_},{B,_}) -> A =< B end, [{1,x},{1,y},{0,z}]) =:= [{0,z},{1,x},{1,y}]")
|
|
"true")
|
|
|
|
(er-lx-test "sort/2 empty"
|
|
(er-lx-nm "lists:sort(fun(A,B) -> A =< B end, []) =:= []") "true")
|
|
|
|
;; ── lists:usort/1 ─────────────────────────────────────────────────
|
|
(er-lx-test "usort/1 removes duplicates"
|
|
(er-lx-nm "lists:usort([3,1,2,1,3]) =:= [1,2,3]") "true")
|
|
|
|
(er-lx-test "usort/1 empty"
|
|
(er-lx-nm "lists:usort([]) =:= []") "true")
|
|
|
|
(er-lx-test "usort/1 all equal collapses to one"
|
|
(er-lx-nm "lists:usort([5,5,5]) =:= [5]") "true")
|
|
|
|
(er-lx-test "usort/1 already unique"
|
|
(er-lx-nm "lists:usort([1,2,3]) =:= [1,2,3]") "true")
|
|
|
|
(er-lx-test "usort/1 length after dedup"
|
|
(erlang-eval-ast "length(lists:usort([4,4,2,2,1,1,4]))") 3)
|