;; lib/minikanren/tests/parity.sx — eveno + oddo Peano predicates.

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

(mk-test "eveno-zero" (run* q (eveno :z)) (list (make-symbol "_.0")))
(mk-test
  "eveno-2"
  (run* q (eveno (mk-nat 2)))
  (list (make-symbol "_.0")))
(mk-test
  "eveno-4"
  (run* q (eveno (mk-nat 4)))
  (list (make-symbol "_.0")))
(mk-test "eveno-1-fails" (run* q (eveno (mk-nat 1))) (list))
(mk-test "eveno-3-fails" (run* q (eveno (mk-nat 3))) (list))

(mk-test
  "oddo-1"
  (run* q (oddo (mk-nat 1)))
  (list (make-symbol "_.0")))
(mk-test
  "oddo-3"
  (run* q (oddo (mk-nat 3)))
  (list (make-symbol "_.0")))
(mk-test "oddo-zero-fails" (run* q (oddo :z)) (list))
(mk-test "oddo-2-fails" (run* q (oddo (mk-nat 2))) (list))

;; Enumerate small evens.
(mk-test
  "eveno-enumerates"
  (run 4 q (eveno q))
  (list
    (mk-nat 0)
    (mk-nat 2)
    (mk-nat 4)
    (mk-nat 6)))

;; Enumerate small odds.
(mk-test
  "oddo-enumerates"
  (run 4 q (oddo q))
  (list
    (mk-nat 1)
    (mk-nat 3)
    (mk-nat 5)
    (mk-nat 7)))

;; A number is even XOR odd (no overlap).
(mk-test
  "even-odd-no-overlap"
  (run*
    q
    (mk-conj (eveno (mk-nat 4)) (oddo (mk-nat 4))))
  (list))

(mk-tests-run!)
