;; lib/minikanren/tests/take-while-drop-while.sx — prefix/suffix by predicate.

(mk-test
  "take-while-o-empty"
  (run* q (take-while-o (fn (x) (== x 1)) (list) q))
  (list (list)))

(mk-test
  "take-while-o-while-lt-5"
  (run*
    q
    (take-while-o
      (fn (x) (lto-i x 5))
      (list 1 3 7 2 9)
      q))
  (list (list 1 3)))

(mk-test
  "take-while-o-all-match"
  (run*
    q
    (take-while-o
      (fn (x) (lto-i x 100))
      (list 1 2 3)
      q))
  (list (list 1 2 3)))

(mk-test
  "take-while-o-none-match"
  (run*
    q
    (take-while-o
      (fn (x) (lto-i 100 x))
      (list 1 2 3)
      q))
  (list (list)))

(mk-test
  "drop-while-o-empty"
  (run* q (drop-while-o (fn (x) (== x 1)) (list) q))
  (list (list)))

(mk-test
  "drop-while-o-while-lt-5"
  (run*
    q
    (drop-while-o
      (fn (x) (lto-i x 5))
      (list 1 3 7 2 9)
      q))
  (list (list 7 2 9)))

(mk-test
  "drop-while-o-all-match"
  (run*
    q
    (drop-while-o
      (fn (x) (lto-i x 100))
      (list 1 2 3)
      q))
  (list (list)))

(mk-test
  "take-drop-roundtrip"
  (run*
    q
    (fresh
      (p s)
      (take-while-o
        (fn (x) (lto-i x 5))
        (list 1 3 7 2 9)
        p)
      (drop-while-o
        (fn (x) (lto-i x 5))
        (list 1 3 7 2 9)
        s)
      (appendo p s q)))
  (list (list 1 3 7 2 9)))

(mk-tests-run!)
