;; lib/minikanren/tests/queens.sx — N-queens, the classic miniKanren benchmark.

;; --- safe-diag (helper) ---

(mk-test
  "safe-diag-different-cols-different-distance"
  (run* q (safe-diag 1 4 2))
  (list (make-symbol "_.0")))

(mk-test
  "safe-diag-same-distance-fails"
  (run* q (safe-diag 1 4 3))
  (list))

(mk-test
  "safe-diag-same-distance-other-direction-fails"
  (run* q (safe-diag 4 1 3))
  (list))

;; --- ino-each / range ---

(mk-test
  "range-1-to-4"
  (range-1-to-n 4)
  (list 1 2 3 4))
(mk-test "range-empty" (range-1-to-n 0) (list))

;; --- 4-queens: two solutions ---

(mk-test
  "queens-4"
  (let
    ((sols (run* q (fresh (a b c d) (== q (list a b c d)) (queens-cols (list a b c d) 4)))))
    (and
      (= (len sols) 2)
      (and
        (some
          (fn (s) (= s (list 2 4 1 3)))
          sols)
        (some
          (fn (s) (= s (list 3 1 4 2)))
          sols))))
  true)

(mk-tests-run!)
