test-find-optimal-join.ss
(module test-find-optimal-join mzscheme
  (require (lib "list.ss")
           (planet "test.ss" ("schematics" "schemeunit.plt" 2 8))
           (planet "text-ui.ss" ("schematics" "schemeunit.plt" 2 8))
           "find-optimal-join.ss")
  
  (define (depth node)
    (cond
      [(number? node)
       node]
      [else
       (add1 (max (depth (first node))
                  (depth (second node))))]))
  
  (define (join f)
    (join-forest f list depth))
  
  (define optimal-join-tests
    (test-suite
     "optimal-join.ss"
     (test-case
      "unary case"
      (check-equal? (join '(1)) 1))
     
     (test-case
      "empty case should raise exn:fail:contract"
      (check-exn exn:fail:contract?
                 (lambda () (join '()))))
     
     (test-case
      "nontrivial case #1"
      (check-equal? (join '(5 10 3 12))
                    '((5 (10 3)) 12)))
     
     (test-case
      "nontrivial case #2"
      (check-equal? (join '(3 2 4 3))
                    '((3 2) (4 3))))
     
     (test-case
      "nontrivial case #3"
      (check-equal? (join '(1 3 2 4))
                    '(1 ((3 2) 4))))
     
     (test-case
      "eight nodes ascending"
      (check-equal? (join '(1 2 3 4 5 6 7 8))
                    '(((((((1 2) 3) 4) 5) 6) 7) 8)))))
  
  
  (test/text-ui optimal-join-tests))