Sha256: 0c3ea21088f6154e4cbc666f7206abbbc77ec58ac169c5fffe991b138c06b293

Contents?: true

Size: 1.33 KB

Versions: 381

Compression:

Stored size: 1.33 KB

Contents

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

(def short-vector [1, 3, 4, 6, 8, 9, 11])

(def large-vector [1, 3, 5, 8, 13, 21, 34, 55, 89])

(def even-length-vector [1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377])

(deftest it-finds-position-of-middle-item
  (is (= 3 (binary-search/middle short-vector))))

(deftest searches-a-singleton
  (is (= 0 (binary-search/search-for 4 [4]))))

(deftest it-finds-position-of-search-data
  (is (= 5 (binary-search/search-for 9 short-vector))))

(deftest it-finds-position-in-a-larger-list
  (is (= 1 (binary-search/search-for 3 large-vector))))

(deftest it-finds-position-in-a-larger-list-again
  (is (= 7 (binary-search/search-for 55 large-vector))))

(deftest it-finds-correct-position-in-a-list-with-an-even-number-of-elements
  (is (= 5 (binary-search/search-for 21 even-length-vector))))

(deftest it-finds-correct-position-in-a-list-with-an-even-number-of-elements-again
  (is (= 6 (binary-search/search-for 34 even-length-vector))))

(deftest it-works-on-lists
  (is (= 7 (binary-search/search-for 7 (range 10)))))

(deftest it-works-on-lists-again
  (is (= 4 (binary-search/search-for 3 '(-3 -2 0 1 3 4)))))

(deftest throws-exception-when-element-not-found
  (is (thrown-with-msg? Throwable #"not found"
        (binary-search/search-for 20 short-vector))))

Version data entries

381 entries across 381 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.179 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.178 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.177 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.176 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.175 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.174 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.173 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.172 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.171 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.170 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.169 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.167 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.166 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.165 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.164 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.163 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.162 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.161 tracks/clojure/exercises/binary-search/test/binary_search_test.clj
trackler-2.2.1.160 tracks/clojure/exercises/binary-search/test/binary_search_test.clj