Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Two conde clauses each: singleton -> the element; multi -> compare head against the recursive min/max of the tail and pick. Uses lteo-i / lto-i for the comparisons, so the input must be ground integers. mino + maxo can run together: (fresh (mn mx) (mino l mn) (maxo l mx) (== q (list mn mx))) recovers both. 9 new tests, 472/472 cumulative.
50 lines
846 B
Plaintext
50 lines
846 B
Plaintext
;; lib/minikanren/tests/minmax.sx — mino + maxo via intarith.
|
|
|
|
(mk-test
|
|
"mino-singleton"
|
|
(run* q (mino (list 7) q))
|
|
(list 7))
|
|
(mk-test
|
|
"mino-of-3"
|
|
(run* q (mino (list 5 1 3) q))
|
|
(list 1))
|
|
(mk-test
|
|
"mino-of-5"
|
|
(run*
|
|
q
|
|
(mino (list 5 1 3 2 4) q))
|
|
(list 1))
|
|
(mk-test
|
|
"mino-with-dups"
|
|
(run* q (mino (list 3 3 3) q))
|
|
(list 3))
|
|
(mk-test "mino-empty-fails" (run* q (mino (list) q)) (list))
|
|
|
|
(mk-test
|
|
"maxo-singleton"
|
|
(run* q (maxo (list 7) q))
|
|
(list 7))
|
|
(mk-test
|
|
"maxo-of-5"
|
|
(run*
|
|
q
|
|
(maxo (list 5 1 3 2 4) q))
|
|
(list 5))
|
|
(mk-test
|
|
"maxo-of-negs"
|
|
(run* q (maxo (list -5 -1 -3) q))
|
|
(list -1))
|
|
|
|
(mk-test
|
|
"min-and-max-of-list"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(mn mx)
|
|
(mino (list 5 1 3 2 4) mn)
|
|
(maxo (list 5 1 3 2 4) mx)
|
|
(== q (list mn mx))))
|
|
(list (list 1 5)))
|
|
|
|
(mk-tests-run!)
|