   [tree]
   (if (ram-empty? tree)
     0
-    (max (inc (height (ltree)))
-         (inc (height (rtree))))))
+    (max (inc (height (ltree tree)))
+         (inc (height (rtree tree))))))
 
 (defn black-height
   "Computes the black height of a tree."

                     (f r)))))]
    (f t)))

(defn actual-count [tree]
  (let [t (.tree tree)]
    (match [t]
           [:black-leaf] 0
           [:double-black-leaf] 0
           [[c l k v s r]] (+ (actual-count l) (actual-count r) 1)
           :else
           (ex-info "Actual count called on a non-tree."
                    {:type :ram-test/actual-count/invalid-input
                     :tree tree})))

(deftest random-access-map-insert-balanced
  "Testing for proper balancing on insert"
  (testing "ALL THE THINGS..."
    (doseq (fn [m]
             (is (balanced? m))
             (is (valid-colors? m)))
             all-maps)))
#_((testing "Inserting a list in ascending order from 1 to 10..."
    (is (balanced? inserted-in-order)))
  (testing "Inserting a list in descending order from 10 to 1..."
    (is (balanced? inserted-in-reverse-order)))
  (testing "Inserting a list in a wierd, but orderly, order..."
    (is (balanced? inserted-in-wierd-order)))
  (testing "Checking an empty set for balance..."
    (is (balanced? (->RandomAccessMap))))
  (testing "Checking for balance of a one-item set..."
    (is (balanced? (i (->RandomAccessMap) 1))))
  (testing "Some good stuff: Inserting a list in ascending order from 1 to 100..."
    (is (balanced? large-set)))
  (testing "Some good stuff: Inserting a list in descending order from 100 to 1..."
    (is (balanced? large-reverse-set))))

#_(deftest random-access-map-remove-balanced
  "Testing the remove part of this"
    (testing "Removed even numbers up to 50 from set of 100..."
      (is (balanced? first-removed-tree)))
    (testing "Removed some numbers but not others from set of 20..."
      (is (balanced? second-removed-tree)))
    (testing "Removing from a list of 10..."
      (is (balanced? even-removed)))
    (testing "Removing from the empty list..."
      (is (= (r (->RandomAccessMap) 1) (->RandomAccessMap))))
    (testing "Removing element that doesn't exist..."
      (is (= first-removed-tree (r first-removed-tree 101)))))

#_(deftest random-access-map-remove-colors
  "Checks colors are correct after removal."
    (testing "Checking colors on first tree..."
      (is (valid-colors? (.tree first-removed-tree))))
    (testing "Checking colors on second removed tree..."
      (is (valid-colors? (.tree second-removed-tree))))
    (testing "Checking colors on even removed tree..."
      (is (valid-colors? (.tree even-removed)))))

#_(deftest random-access-map-index-remove-balanced
  "Testing the remove part of this"
    (testing "Removed every third index from 0 to 40 from a set of 100..."
      (is (balanced? first-index-removed-tree)))
    (testing "Removed by some indexes but not by others from a set of 10..."
      (is (balanced? second-index-removed-tree)))
    (testing "Removing by index from a list of 10 from the end..."
      (is (balanced? end-index-removed-tree)))
    (testing "Removing by index from a list of 10 from the beginning..."
      (is (balanced? end-index-removed-tree)))
    (testing "Removing from the empty list..."
      (is (= (rn (->RandomAccessMap) 0) (->RandomAccessMap))))
    (testing "Removing element that doesn't exist..."
      (is (= first-removed-tree (rn first-removed-tree 101)))))

#_(deftest random-access-map-index-remove-colors
  "Checks colors are correct after removal."
    (testing "Checking colors on first index-removed tree..."
      (is (valid-colors? (.tree first-index-removed-tree))))
    (testing "Checking colors on second index-removed tree..."
      (is (valid-colors? (.tree second-index-removed-tree))))
    (testing "Checking colors on start indexed removed tree..."
      (is (valid-colors? (.tree start-index-removed-tree))))
    (testing "Checking colors on end indexed removed tree..."
      (is (valid-colors? (.tree end-index-removed-tree)))))



#_(deftest count-enforced
  "Check to see that all sizes are everywhere correct in the tree."
  (testing "Checking empty set..."
    (is (= (actual-count (empty-ram)) (size (empty-ram)) 0)))
  (testing "Checking inserted-in-order set..."
    (is (= (actual-count (.tree inserted-in-order)) (count inserted-in-order))))
  (testing "Checking inserted-in-reverse-order set..."
    (is (= (actual-count (.tree inserted-in-reverse-order)) (count inserted-in-reverse-order))))
  (testing "Checking inserted-in-wierd-order set..."
    (is (= (actual-count (.tree inserted-in-wierd-order)) (count inserted-in-wierd-order))))
  (testing "Checking large-set set..."
    (is (= (actual-count (.tree large-set)) (count large-set))))
  (testing "Checking large-reverse-set set..."
    (is (= (actual-count (.tree large-reverse-set)) (count large-reverse-set))))
  (testing "Checking first-removed-tree set..."
    (is (= (actual-count (.tree first-removed-tree)) (count first-removed-tree))))
  (testing "Checking second-removed-tree set..."
    (is (= (actual-count (.tree second-removed-tree)) (count second-removed-tree))))
  (testing "Checking even-removed set..."
    (is (= (actual-count (.tree even-removed)) (count even-removed))))
  (testing "Checking second-removed-tree set..."
    (is (= (actual-count (.tree second-removed-tree)) (count second-removed-tree))))
  (testing "Checking first-indexed-removed-tree set..."
    (is (= (actual-count (.tree first-indexed-removed-tree)) (count second-removed-tree))))
  (testing "Checking second-indexed-removed-tree set..."
    (is (= (actual-count (.tree second-indexed-removed-tree)) (count second-removed-tree))))
  (testing "Checking start-indexed-removed-tree set..."
    (is (= (actual-count (.tree start-indexed-removed-tree)) (count second-removed-tree))))
  (testing "Checking end-indexed-removed-tree set..."
    (is (= (actual-count (.tree end-indexed-removed-tree)) (count second-removed-tree)))))

;; UNCOMMENT THIS
#_(deftest test-ram-find
  "Test ram-find"
  (testing "Testing find for inserted-in-order..."
    (is (= (find inserted-in-order :1) (clojure.lang.MapEntry. :1 1)))
    (is (= (find inserted-in-order :4) (clojure.lang.MapEntry. :4 4)))
    (is (= (find inserted-in-order :7) (clojure.lang.MapEntry. :7 7))))
  (testing "Testing find for inserted-in-reverse-order..."
    (is (= (find inserted-in-reverse-order :2) (clojure.lang.MapEntry. :2 2)))
    (is (= (find inserted-in-reverse-order :3) (clojure.lang.MapEntry. :3 3)))
    (is (= (find inserted-in-reverse-order :8) (clojure.lang.MapEntry. :8 8))))
  (testing "Testing find for inserted-in-wierd-order..."
    (is (= (find inserted-in-wierd-order :5) (clojure.lang.MapEntry. :5 1)))
    (is (= (find inserted-in-wierd-order :6) (clojure.lang.MapEntry. :6 4)))
    (is (= (find inserted-in-wierd-order :9) (clojure.lang.MapEntry. :9 7))))

;; inserted-in-reverse-order
;; inserted-in-wierd-order
;; large-reverse-set
;; first-removed-tree
;; second-removed-tree
;; even-removed
;; first-index-removed-tree
;; second-index-removed-tree
;; start-index-removed-tree
;; end-index-removed-tree



  (testing "Find a value in the set..."
    (is (= (get inserted-in-order :1) 1)))
  (testing "Don't find a value in the set..."
    (is (nil? (get inserted-in-order :11))))
  (testing "Don't find anything in the empty set..."
    (is (nil? (get (->RandomAccessMap) :1)))))

;; UNCOMMENT THIS
#_(deftest get-by-rank-test
  "Find out if get-by-rank works."
  (testing "Checking rank on odd-numbered set..."
    (is (= (nth (nth even-removed 0) 1) 1))
    (is (= (nth (nth even-removed 1) 1) 3))
    (is (= (nth (nth even-removed 2) 1) 5))
    (is (= (nth (nth even-removed 3) 1) 7))
    (is (= (nth (nth even-removed 4) 1) 9)))
  (testing "Checking exception"
    (is (thrown-with-msg? clojure.lang.ExceptionInfo
                          #"Index out of bounds."
                          (nth even-removed 5)))
    (is (thrown-with-msg? clojure.lang.ExceptionInfo
                          #"Index out of bounds."
                          (nth even-removed -1))))
    (testing "Checking default value"
      (is (= (nth even-removed 87 :armadillo) :armadillo))
      (is (= (nth even-removed 303 nil) nil))
      (is (= (nth even-removed -1 "whodj") "whodj"))))

             (<= lh (+ (* 2 rh) 1))
             true))
         (naive-balanced? l)
         (naive-balanced? r)))))

(defn balanced?
  "Determines if a red-black tree is balanced"
