;; 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!)
