;; lib/minikanren/tests/foldl-o.sx — relational left fold.

(mk-test
  "foldl-o-empty"
  (run* q (foldl-o pluso-i (list) 42 q))
  (list 42))

(mk-test
  "foldl-o-sum"
  (run*
    q
    (foldl-o
      pluso-i
      (list 1 2 3 4 5)
      0
      q))
  (list 15))

(mk-test
  "foldl-o-product"
  (run*
    q
    (foldl-o
      *o-i
      (list 1 2 3 4)
      1
      q))
  (list 24))

(mk-test
  "foldl-o-reverse-via-flip-conso"
  (run*
    q
    (foldl-o
      (fn (acc x r) (conso x acc r))
      (list 1 2 3 4)
      (list)
      q))
  (list (list 4 3 2 1)))

(mk-test
  "foldl-o-with-init"
  (run*
    q
    (foldl-o pluso-i (list 1 2 3) 100 q))
  (list 106))

(mk-tests-run!)
