;; lib/minikanren/tests/clpfd-plus.sx — fd-plus (x + y = z).

(mk-test
  "fd-plus-all-ground"
  (run* q (fresh (z) (fd-plus 2 3 z) (== q z)))
  (list 5))

(mk-test
  "fd-plus-recover-x"
  (run* q (fresh (x) (fd-plus x 3 5) (== q x)))
  (list 2))

(mk-test
  "fd-plus-recover-y"
  (run* q (fresh (y) (fd-plus 2 y 5) (== q y)))
  (list 3))

(mk-test
  "fd-plus-impossible-fails"
  (run*
    q
    (fresh
      (z)
      (fd-plus 2 3 z)
      (== z 99)
      (== q z)))
  (list))

(mk-test
  "fd-plus-domain-check"
  (run*
    q
    (fresh
      (x)
      (fd-in x (list 3 4 5))
      (fd-plus x 3 5)
      (== q x)))
  (list))

(mk-test
  "fd-plus-pairs-summing-to-5"
  (run*
    q
    (fresh
      (x y)
      (fd-in x (list 1 2 3 4))
      (fd-in y (list 1 2 3 4))
      (fd-plus x y 5)
      (fd-label (list x y))
      (== q (list x y))))
  (list
    (list 1 4)
    (list 2 3)
    (list 3 2)
    (list 4 1)))

(mk-test
  "fd-plus-z-derived"
  (run* q (fresh (z) (fd-plus 7 8 z) (== q z)))
  (list 15))

(mk-tests-run!)
