Sha256: 5692fec184e96c7a63aca97cd1b406e1bf9c51e04b671f80d6d7472365aeb75b

Contents?: true

Size: 1.34 KB

Versions: 396

Compression:

Stored size: 1.34 KB

Contents

(ns binary-search-tree-test
  (:require [clojure.test :refer [deftest is]]
            [binary-search-tree :as bst]))

(deftest data-is-retained
  (is (= 4 (bst/value (bst/singleton 4)))))

(deftest inserting-less
  (let [t (bst/insert 2 (bst/singleton 4))]
    (is (= 4 (bst/value t)))
    (is (= 2 (bst/value (bst/left t))))))

(deftest inserting-same
  (let [t (bst/insert 4 (bst/singleton 4))]
    (is (= 4 (bst/value t)))
    (is (= 4 (bst/value (bst/left t))))))

(deftest inserting-right
  (let [t (bst/insert 5 (bst/singleton 4))]
    (is (= 4 (bst/value t)))
    (is (= 5 (bst/value (bst/right t))))))

(deftest complex-tree
  (let [t (bst/from-list [4 2 6 1 3 7 5])]
    (is (= 4 (bst/value t)))
    (is (= 2 (bst/value (bst/left t))))
    (is (= 1 (bst/value (bst/left (bst/left t)))))
    (is (= 3 (bst/value (bst/right (bst/left t)))))
    (is (= 6 (bst/value (bst/right t))))
    (is (= 5 (bst/value (bst/left (bst/right t)))))
    (is (= 7 (bst/value (bst/right (bst/right t)))))))

(deftest iterating-one-element
  (is (= [4] (bst/to-list (bst/singleton 4)))))

(deftest iterating-over-smaller-element
  (is (= [2 4] (bst/to-list (bst/from-list [4 2])))))

(deftest iterating-over-larger-element
  (is (= [4 5] (bst/to-list (bst/from-list [4 5])))))

(deftest iterating-over-complex-tree
  (is (= (range 1 8) (bst/to-list (bst/from-list [4 2 1 3 6 7 5])))))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.138 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.137 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.136 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.135 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.134 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.133 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.132 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.131 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.130 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.129 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.128 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.127 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.126 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.125 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.124 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.123 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.122 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.121 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.120 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj