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.180 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.179 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.178 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.177 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.176 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.175 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.174 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.173 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.172 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.171 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.170 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.169 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.167 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.166 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.165 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.164 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.163 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.162 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.161 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.160 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj