;; lib/minikanren/tests/repeato-concato.sx — repeat element n times +
;; concatenate a list of lists.

(define
  mk-nat
  (fn (n) (if (= n 0) :z (list :s (mk-nat (- n 1))))))

;; --- repeato ---

(mk-test
  "repeato-zero"
  (run* q (repeato :a (mk-nat 0) q))
  (list (list)))
(mk-test
  "repeato-one"
  (run* q (repeato :a (mk-nat 1) q))
  (list (list :a)))
(mk-test
  "repeato-three"
  (run* q (repeato :a (mk-nat 3) q))
  (list (list :a :a :a)))

(mk-test
  "repeato-numeric"
  (run* q (repeato 7 (mk-nat 4) q))
  (list (list 7 7 7 7)))

(mk-test
  "repeato-recover-count"
  (run* q (repeato :x q (list :x :x :x :x)))
  (list (mk-nat 4)))

;; --- concato ---

(mk-test "concato-empty" (run* q (concato (list) q)) (list (list)))

(mk-test
  "concato-single"
  (run* q (concato (list (list 1 2 3)) q))
  (list (list 1 2 3)))

(mk-test
  "concato-multi"
  (run*
    q
    (concato
      (list
        (list 1 2)
        (list 3)
        (list 4 5 6))
      q))
  (list
    (list 1 2 3 4 5 6)))

(mk-test
  "concato-all-empty"
  (run* q (concato (list (list) (list) (list)) q))
  (list (list)))

(mk-test
  "concato-mixed-empty"
  (run*
    q
    (concato
      (list (list 1) (list) (list 2 3))
      q))
  (list (list 1 2 3)))

(mk-tests-run!)
