ocaml: phase 6 List.sort + compare (+7 tests, 339 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s

compare is a host builtin returning -1/0/1 (Stdlib.compare semantics)
deferred to host SX </>. List.sort is insertion-sort in OCaml: O(n²)
but works correctly. List.stable_sort = sort.

Tested: ascending int sort, descending via custom comparator (b - a),
empty list, string sort.
This commit is contained in:
2026-05-08 12:59:50 +00:00
parent 812aa75d43
commit 202ea9cf5f
4 changed files with 54 additions and 2 deletions

View File

@@ -828,6 +828,22 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 1605)
(eval "(ocaml-run-program \"let t = Hashtbl.create 10;; Hashtbl.add t \\\"k\\\" 5;; Hashtbl.find_opt t \\\"k\\\"\")")
;; ── List.sort + compare ────────────────────────────────────────
(epoch 1700)
(eval "(ocaml-run \"compare 1 2\")")
(epoch 1701)
(eval "(ocaml-run \"compare 5 5\")")
(epoch 1702)
(eval "(ocaml-run \"compare 9 1\")")
(epoch 1703)
(eval "(ocaml-run \"List.sort compare [3; 1; 4; 1; 5; 9; 2; 6]\")")
(epoch 1704)
(eval "(ocaml-run \"List.sort (fun a b -> b - a) [3; 1; 4]\")")
(epoch 1705)
(eval "(ocaml-run \"List.sort compare []\")")
(epoch 1706)
(eval "(ocaml-run \"List.sort compare [\\\"b\\\"; \\\"a\\\"; \\\"c\\\"]\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1310,6 +1326,15 @@ check 1603 "Hashtbl mem" 'true'
check 1604 "Hashtbl replace" '2'
check 1605 "Hashtbl find_opt found" '("Some" 5)'
# ── List.sort + compare ─────────────────────────────────────────
check 1700 "compare 1<2" '-1'
check 1701 "compare 5=5" '0'
check 1702 "compare 9>1" '1'
check 1703 "List.sort ascending" '(1 1 2 3 4 5 6 9)'
check 1704 "List.sort descending" '(4 3 1)'
check 1705 "List.sort empty" '()'
check 1706 "List.sort strings" '("a" "b" "c")'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"