;; lib/minikanren/tests/rev-acco.sx — accumulator-style reverse.
;;
;; Faster than reverseo for forward queries (no quadratic appendos).
;; Trade-off: rev-acco is asymmetric (acc=initial-empty for the public
;; interface), so it does not cleanly run backwards in run* the way
;; reverseo does.

(mk-test "rev-2o-empty" (run* q (rev-2o (list) q)) (list (list)))

(mk-test
  "rev-2o-singleton"
  (run* q (rev-2o (list 7) q))
  (list (list 7)))

(mk-test
  "rev-2o-three"
  (run* q (rev-2o (list 1 2 3) q))
  (list (list 3 2 1)))

(mk-test
  "rev-2o-five"
  (run*
    q
    (rev-2o (list 1 2 3 4 5) q))
  (list (list 5 4 3 2 1)))

(mk-test
  "rev-2o-strings"
  (run* q (rev-2o (list "a" "b" "c") q))
  (list (list "c" "b" "a")))

(mk-test
  "rev-2o-reverseo-agree"
  (let
    ((via-reverseo (first (run* q (reverseo (list 1 2 3 4 5) q))))
      (via-rev-2o
        (first
          (run*
            q
            (rev-2o
              (list 1 2 3 4 5)
              q)))))
    (= via-reverseo via-rev-2o))
  true)

(mk-tests-run!)
