Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 54s
rembero (remove-first) uses nafc to gate the skip-element clause so the result is well-defined on ground lists. assoco is alist lookup — runs forward (key -> value) and backward (find keys with a given value). nth-o uses Peano-encoded indices into a list, mirroring lengtho. 13 new tests, 266/266 cumulative.
90 lines
1.5 KiB
Plaintext
90 lines
1.5 KiB
Plaintext
;; lib/minikanren/tests/list-relations.sx — rembero, assoco, nth-o.
|
|
|
|
;; --- rembero (remove first occurrence) ---
|
|
|
|
(mk-test
|
|
"rembero-element-present"
|
|
(run*
|
|
q
|
|
(rembero 2 (list 1 2 3 2) q))
|
|
(list (list 1 3 2)))
|
|
|
|
(mk-test
|
|
"rembero-element-not-present"
|
|
(run* q (rembero 99 (list 1 2 3) q))
|
|
(list (list 1 2 3)))
|
|
|
|
(mk-test
|
|
"rembero-empty"
|
|
(run* q (rembero 1 (list) q))
|
|
(list (list)))
|
|
|
|
(mk-test
|
|
"rembero-only-element"
|
|
(run* q (rembero 5 (list 5) q))
|
|
(list (list)))
|
|
|
|
(mk-test
|
|
"rembero-first-of-many"
|
|
(run*
|
|
q
|
|
(rembero 1 (list 1 2 3 4) q))
|
|
(list (list 2 3 4)))
|
|
|
|
;; --- assoco (alist lookup) ---
|
|
|
|
(define
|
|
test-pairs
|
|
(list
|
|
(list "alice" 30)
|
|
(list "bob" 25)
|
|
(list "carol" 35)))
|
|
|
|
(mk-test
|
|
"assoco-found"
|
|
(run* q (assoco "bob" test-pairs q))
|
|
(list 25))
|
|
|
|
(mk-test
|
|
"assoco-first"
|
|
(run* q (assoco "alice" test-pairs q))
|
|
(list 30))
|
|
|
|
(mk-test "assoco-missing" (run* q (assoco "dave" test-pairs q)) (list))
|
|
|
|
(mk-test
|
|
"assoco-find-keys-with-value"
|
|
(run* q (assoco q test-pairs 25))
|
|
(list "bob"))
|
|
|
|
;; --- nth-o (Peano-indexed access) ---
|
|
|
|
(mk-test
|
|
"nth-o-zero"
|
|
(run* q (nth-o :z (list 10 20 30) q))
|
|
(list 10))
|
|
|
|
(mk-test
|
|
"nth-o-one"
|
|
(run* q (nth-o (list :s :z) (list 10 20 30) q))
|
|
(list 20))
|
|
|
|
(mk-test
|
|
"nth-o-two"
|
|
(run*
|
|
q
|
|
(nth-o (list :s (list :s :z)) (list 10 20 30) q))
|
|
(list 30))
|
|
|
|
(mk-test
|
|
"nth-o-out-of-range"
|
|
(run*
|
|
q
|
|
(nth-o
|
|
(list :s (list :s (list :s :z)))
|
|
(list 10 20 30)
|
|
q))
|
|
(list))
|
|
|
|
(mk-tests-run!)
|