Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Sum and product over a list of ground integers via fold + intarith. Empty list yields the identity (0 for sum, 1 for product). Recurse combines the head with the recursively-computed tail value via pluso-i / *o-i. 9 new tests, 481/481 cumulative.
45 lines
858 B
Plaintext
45 lines
858 B
Plaintext
;; lib/minikanren/tests/sum-product.sx — fold list to integer.
|
|
|
|
(mk-test "sumo-empty" (run* q (sumo (list) q)) (list 0))
|
|
(mk-test
|
|
"sumo-1-to-5"
|
|
(run*
|
|
q
|
|
(sumo (list 1 2 3 4 5) q))
|
|
(list 15))
|
|
(mk-test
|
|
"sumo-zeros"
|
|
(run* q (sumo (list 0 0 0) q))
|
|
(list 0))
|
|
(mk-test
|
|
"sumo-negs"
|
|
(run* q (sumo (list 5 -3 8) q))
|
|
(list 10))
|
|
|
|
(mk-test "producto-empty" (run* q (producto (list) q)) (list 1))
|
|
(mk-test
|
|
"producto-1-to-4"
|
|
(run* q (producto (list 1 2 3 4) q))
|
|
(list 24))
|
|
(mk-test
|
|
"producto-with-0"
|
|
(run* q (producto (list 5 0 7) q))
|
|
(list 0))
|
|
(mk-test
|
|
"producto-of-1s"
|
|
(run* q (producto (list 1 1 1) q))
|
|
(list 1))
|
|
|
|
(mk-test
|
|
"sum-product-pythagorean-square"
|
|
(run*
|
|
q
|
|
(fresh
|
|
(s sq2)
|
|
(sumo (list 3 4 5) s)
|
|
(producto (list 3 3) sq2)
|
|
(== q (list s sq2))))
|
|
(list (list 12 9)))
|
|
|
|
(mk-tests-run!)
|