;; lib/minikanren/tests/predicates.sx — everyo, someo.

;; --- everyo ---

(mk-test
  "everyo-empty-trivially-true"
  (run* q (everyo (fn (x) (== x 1)) (list)))
  (list (make-symbol "_.0")))

(mk-test
  "everyo-all-match"
  (run*
    q
    (everyo
      (fn (x) (== x 1))
      (list 1 1 1)))
  (list (make-symbol "_.0")))

(mk-test
  "everyo-some-mismatch"
  (run*
    q
    (everyo
      (fn (x) (== x 1))
      (list 1 2 1)))
  (list))

(mk-test
  "everyo-with-intarith"
  (run*
    q
    (everyo
      (fn (x) (lto-i x 10))
      (list 1 5 9)))
  (list (make-symbol "_.0")))

(mk-test
  "everyo-with-intarith-fail"
  (run*
    q
    (everyo
      (fn (x) (lto-i x 5))
      (list 1 5 9)))
  (list))

;; --- someo ---

(mk-test
  "someo-finds-element"
  (run*
    q
    (someo
      (fn (x) (== x 2))
      (list 1 2 3)))
  (list (make-symbol "_.0")))

(mk-test
  "someo-not-found"
  (run*
    q
    (someo
      (fn (x) (== x 99))
      (list 1 2 3)))
  (list))

(mk-test
  "someo-empty-fails"
  (run* q (someo (fn (x) (== x 1)) (list)))
  (list))

(mk-test
  "someo-multiple-matches-yields-multiple"
  (let
    ((res (run* q (fresh (x) (someo (fn (y) (== y x)) (list 1 2 1)) (== q x)))))
    (len res))
  3)

(mk-test
  "someo-with-intarith"
  (run*
    q
    (someo
      (fn (x) (lto-i 100 x))
      (list 5 50 200)))
  (list (make-symbol "_.0")))

(mk-tests-run!)
