(library-directories "./..") (print-gensym #f)
(import (patricia))

(define (random-list hi n)
  (if (= n 0)
      '()
      (cons (random hi) (random-list hi (1- n)))))
(define T10 (fold-right insert empty (iota 10) (iota 10)))
(define (mkt xs)
  (fold-right insert empty xs xs))
(define (happens? n)
  (do ((i 0 (1+ i)))
      ((= i n))
    (merge-with + (mkt (random-list 10000000 10000)) (mkt (random-list 10000000 10000)))))
(assert (zero? (tree-size empty)))
(assert (empty? empty))
(assert (= 1 (tree-size (insert 0 0 empty))))
(assert (not (lookup 1 (insert 0 0 empty))))
(let ((S (fold-right insert empty (reverse (iota 10)) (reverse (iota 10)))))
  (assert (tree-equal? S T10)))
(assert (equal? (iota 10) (tree->keys T10)))
(assert (equal? (iota 10)
                (tree->keys
                 (fold-right insert empty (reverse (iota 10)) (iota 10)))))
(assert (equal? (iota 10)
                (tree->keys
                 (fold-right insert empty (reverse (iota 10)) (iota 10)))))
(assert (equal? (iota 5) (tree->keys (split< 5 T10))))
(assert (equal? (iota 6) (tree->keys (split<= 5 T10))))
(assert (equal? '(6 7 8 9) (tree->keys (split> 5 T10))))
(assert (equal? '(5 6 7 8 9) (tree->keys (split>= 5 T10))))
(assert (tree-equal? T10 (symmetric-difference (split< 5 T10) (split>= 5 T10))))
(assert (tree-equal? T10 (symmetric-difference (split<= 5 T10) (split> 5 T10))))
