;; lib/minikanren/tests/nub-o.sx — relational dedupe (keep last occurrence).

(mk-test "nub-o-empty" (run* q (nub-o (list) q)) (list (list)))

(mk-test
  "nub-o-no-duplicates"
  (run* q (nub-o (list 1 2 3) q))
  (list (list 1 2 3)))

(mk-test
  "nub-o-with-duplicates"
  (run*
    q
    (nub-o
      (list 1 2 1 3 2 4)
      q))
  (list (list 1 3 2 4)))

(mk-test
  "nub-o-all-same"
  (let
    ((res (run* q (nub-o (list 1 1 1) q))))
    (every? (fn (r) (= r (list 1))) res))
  true)

(mk-test
  "nub-o-keeps-last"
  (run* q (nub-o (list 1 2 1) q))
  (list (list 2 1)))

(mk-tests-run!)
