Skip to content

Commit

Permalink
Merge pull request #1046 from hexlet-codebattle/fix-binary-search-gen…
Browse files Browse the repository at this point in the history
…erator
  • Loading branch information
solar05 authored Sep 5, 2023
2 parents 9f986ef + 17a3d85 commit 71fb5d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/battle_asserts/issues/binary_search.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
{:argument-name "target" :type {:name "integer"}}]
:output {:type {:name "integer"}}})

(defn generate-elements []
(vec (sort (distinct (gen/generate (gen/vector (gen/choose 2 121) 10 50))))))

(defn arguments-generator []
(gen/tuple (gen/vector (gen/choose 2 121) 10 128) (gen/choose 1 142)))
(let [collections (vec (repeatedly 40 generate-elements))]
(gen/tuple (gen/elements collections) (gen/choose 1 135))))

(def test-data
[{:expected 1 :arguments [[1 2 2 2 3 4 5] 2]}
{:expected 0 :arguments [[1 1 1 1 1 1 1] 1]}
{:expected 4 :arguments [[-10 -5 0 4 7 9 11 11 13 14 15] 7]}
{:expected -1 :arguments [[1 2 3 4 5] 6]}])
; {:expected -1 :arguments [[] 42]}])

(defn solution [sorted-list target]
(let [lo 0
Expand Down
4 changes: 3 additions & 1 deletion test/test_helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(def difficulties #{:elementary :easy :medium :hard})

(defn- check-output-type [data]
(if (or (= (type data) java.lang.Integer) (= (type data) java.lang.Long)) ; for backward compatibility
(if (or (= (type data) java.lang.Integer) (= (type data) java.lang.Long)) ; for backward compatibility
java.lang.Long
(type data)))

Expand All @@ -17,6 +17,7 @@
(defn- nested? [element]
(contains?
#{clojure.lang.PersistentList
clojure.lang.ArraySeq
clojure.lang.PersistentArrayMap
clojure.lang.PersistentVector}
(type element)))
Expand All @@ -28,6 +29,7 @@
java.lang.Double "float"
java.lang.Boolean "boolean"
clojure.lang.Ratio "integer"
clojure.lang.ArraySeq "array"
clojure.lang.PersistentList "array"
clojure.lang.PersistentVector "array"
clojure.lang.PersistentArrayMap "hash"
Expand Down

0 comments on commit 71fb5d8

Please sign in to comment.