(import tree miscmacros srfi-1) (define frotz '(a (b c (d (e f) (g h)) (i j k)))) (unless (equal? '((a (b c (d (e f) (g h)) (i j k))) a (b c (d (e f) (g h)) (i j k)) b c (d (e f) (g h)) d (e f) e f (g h) g h (i j k) i j k) (let ((mine '())) (tree-walk-preorder (lambda (n) (push! n mine)) frotz) (reverse mine))) (error "(let ((mine (quote ()))) (tree-walk-preorder (lambda (n) (push! n mine)) frotz) (reverse mine))")) (unless (equal? '(a b c d e f (e f) g h (g h) (d (e f) (g h)) i j k (i j k) (b c (d (e f) (g h)) (i j k)) (a (b c (d (e f) (g h)) (i j k)))) (let ((mine '())) (tree-walk-postorder (lambda (n) (push! n mine)) frotz) (reverse mine))) (error "(let ((mine (quote ()))) (tree-walk-postorder (lambda (n) (push! n mine)) frotz) (reverse mine))")) (unless (equal? '((a (b c (d (e f) (g h)) (i j k))) a (b c (d (e f) (g h)) (i j k)) b c (d (e f) (g h)) (i j k) d (e f) (g h) i j k e f g h) (let ((mine '())) (tree-walk-breadth-first (lambda (n) (push! n mine)) frotz) (reverse mine))) (error "(let ((mine (quote ()))) (tree-walk-breadth-first (lambda (n) (push! n mine)) frotz) (reverse mine))")) (unless (equal? '#t (tree? frotz)) (error "(tree? frotz)")) (unless (equal? '#t (tree=? eq? frotz (tree-copy frotz))) (error "(tree=? eq? frotz (tree-copy frotz))")) (unless (equal? '("a" ("b" "c" ("d" ("e" "f") ("g" "h")) ("i" "j" "k"))) (tree-map symbol->string frotz)) (error "(tree-map symbol->string frotz)")) (define vowel-sym? (cut member <> '(a e i o u))) (unless (equal? '3 (tree-count vowel-sym? frotz)) (error "(tree-count vowel-sym? frotz)")) (unless (equal? '#t (tree-any? vowel-sym? frotz)) (error "(tree-any? vowel-sym? frotz)")) (unless (equal? '#f (tree-any? (constantly #f) frotz)) (error "(tree-any? (constantly #f) frotz)")) (unless (equal? '#t (tree-any? (constantly #t) frotz)) (error "(tree-any? (constantly #t) frotz)")) (unless (equal? '#f (tree-every? vowel-sym? frotz)) (error "(tree-every? vowel-sym? frotz)")) (unless (equal? '#f (tree-every? (constantly #f) frotz)) (error "(tree-every? (constantly #f) frotz)")) (unless (equal? '#t (tree-every? (constantly #t) frotz)) (error "(tree-every? (constantly #t) frotz)")) (unless (equal? 'a (tree-find vowel-sym? frotz #f)) (error "(tree-find vowel-sym? frotz #f)")) (unless (equal? 'b (tree-find (conjoin atom? (complement vowel-sym?)) frotz #f)) (error "(tree-find (conjoin atom? (complement vowel-sym?)) frotz #f)")) (unless (equal? 'g (tree-find-equal? frotz 'g)) (error "(tree-find-equal? frotz (quote g))")) (unless (equal? '#t (tree-atoms-any? vowel-sym? frotz)) (error "(tree-atoms-any? vowel-sym? frotz)")) (unless (equal? '#f (tree-atoms-any? (constantly #f) frotz)) (error "(tree-atoms-any? (constantly #f) frotz)")) (unless (equal? '#t (tree-atoms-any? (constantly #t) frotz)) (error "(tree-atoms-any? (constantly #t) frotz)")) (unless (equal? '#f (tree-atoms-every? vowel-sym? frotz)) (error "(tree-atoms-every? vowel-sym? frotz)")) (unless (equal? '#f (tree-atoms-every? (constantly #f) frotz)) (error "(tree-atoms-every? (constantly #f) frotz)")) (unless (equal? '#t (tree-atoms-every? (constantly #t) frotz)) (error "(tree-atoms-every? (constantly #t) frotz)")) (define ifrotz (invert-tree frotz)) (unless (equal? '(d (e f) (g h)) (tree-parent ifrotz (caddr (caddr (cadr frotz))))) (error "(tree-parent ifrotz (caddr (caddr (cadr frotz))))")) (unless (equal? '3 (tree-depth ifrotz (caddr (caddr (cadr frotz))))) (error "(tree-depth ifrotz (caddr (caddr (cadr frotz))))")) (unless (equal? '2 (tree-local-position ifrotz (caddr (caddr (cadr frotz))))) (error "(tree-local-position ifrotz (caddr (caddr (cadr frotz))))")) (unless (equal? '#t (tree-contains? ifrotz (caddr (caddr (cadr frotz))))) (error "(tree-contains? ifrotz (caddr (caddr (cadr frotz))))")) (unless (equal? '#t (tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (cadr (caddr (cadr frotz))))) (error "(tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (cadr (caddr (cadr frotz))))")) (unless (equal? '#f (tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (caddr (cadr frotz)))) (error "(tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (caddr (cadr frotz)))")) (unless (equal? '#f (tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (cadr (cadr frotz)))) (error "(tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (cadr (cadr frotz)))")) (unless (equal? '#f (tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (caddr (cdadr frotz)))) (error "(tree-c-commands? ifrotz (caddr (caddr (cadr frotz))) (caddr (cdadr frotz)))")) (unless (equal? '((g h) (d (e f) (g h)) (b c (d (e f) (g h)) (i j k)) (a (b c (d (e f) (g h)) (i j k)))) (tree-path ifrotz (caddr (caddr (cadr frotz))))) (error "(tree-path ifrotz (caddr (caddr (cadr frotz))))")) (unless (equal? '(a (b c (my long-winded journey) (i j k))) (tree-replace ifrotz (cadr (cdadr frotz)) '(my long-winded journey))) (error "(tree-replace ifrotz (cadr (cdadr frotz)) (quote (my long-winded journey)))")) (unless (equal? '(a (b c (d (e f) (g h) (my long-winded journey)) (i j k))) (tree-add ifrotz (cadr (cdadr frotz)) '(my long-winded journey))) (error "(tree-add ifrotz (cadr (cdadr frotz)) (quote (my long-winded journey)))")) (unless (equal? '(a (b c (d (my long-winded journey) (e f) (g h)) (i j k))) (tree-insert ifrotz (cadr (cdadr frotz)) 1 '(my long-winded journey))) (error "(tree-insert ifrotz (cadr (cdadr frotz)) 1 (quote (my long-winded journey)))")) (unless (equal? '(a (b c (i j k))) (tree-prune ifrotz (cadr (cdadr frotz)))) (error "(tree-prune ifrotz (cadr (cdadr frotz)))")) (unless (equal? '(a (b c (i j k (d (e f) (g h))))) (tree-move ifrotz (cadr (cdadr frotz)) (last (last frotz)))) (error "(tree-move ifrotz (cadr (cdadr frotz)) (last (last frotz)))")) (unless (and (equal? (tree-remove (lambda (x) (and (pair? x) (member (car x) '(g i)))) frotz) '(a (b c (d (e f))))) (equal? frotz '(a (b c (d (e f) (g h)) (i j k))))) (error "tree-remove is not doing great"))