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.119 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.118 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.117 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.116 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.115 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.114 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.113 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.111 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.110 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.109 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.108 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.107 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.106 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.105 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.104 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.103 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.102 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.101 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.100 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj
trackler-2.2.1.99 tracks/clojure/exercises/binary-search-tree/test/binary_search_tree_test.clj