;; lib/minikanren/tests/mapo.sx — relational map.

(mk-test
  "mapo-identity"
  (run*
    q
    (mapo (fn (a b) (== a b)) (list 1 2 3) q))
  (list (list 1 2 3)))

(mk-test
  "mapo-tag-each"
  (run*
    q
    (mapo
      (fn (a b) (== b (list :tag a)))
      (list 1 2 3)
      q))
  (list
    (list
      (list :tag 1)
      (list :tag 2)
      (list :tag 3))))

(mk-test
  "mapo-backward"
  (run*
    q
    (mapo (fn (a b) (== a b)) q (list 1 2 3)))
  (list (list 1 2 3)))

(mk-test
  "mapo-empty"
  (run* q (mapo (fn (a b) (== a b)) (list) q))
  (list (list)))

(mk-test
  "mapo-duplicate"
  (run* q (mapo (fn (a b) (== b (list a a))) (list :x :y) q))
  (list (list (list :x :x) (list :y :y))))

(mk-test
  "mapo-different-length-fails"
  (run*
    q
    (mapo
      (fn (a b) (== a b))
      (list 1 2)
      (list 1 2 3)))
  (list))

;; mapo + arithmetic via intarith
(mk-test
  "mapo-square-each"
  (run*
    q
    (mapo
      (fn (a b) (*o-i a a b))
      (list 1 2 3 4)
      q))
  (list (list 1 4 9 16)))

(mk-tests-run!)
