Skip to content

Commit

Permalink
Add solution for jackpot task (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
solar05 committed Sep 2, 2020
1 parent 96035d9 commit 94f6489
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/battle_asserts/issues/jackpot.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns battle-asserts.issues.jackpot
(:require [clojure.test.check.generators :as gen]
[faker.generate :as faker]))

(def level :elementary)

(def description "Create a function that takes in an array (slot machine outcome)
and returns true if all elements in the array are identical, and false otherwise.
The array will contain 4 elements.")

(def signature
{:input [{:argument-name "elements" :type {:name "array" :nested {:name "string"}}}]
:output {:type {:name "boolean"}}})

(defn arguments-generator []
(let [element (gen/elements (faker/words {:lang :en :n 5}))]
(gen/tuple (gen/tuple element element element element))))

(def test-data
[{:expected true :arguments [["9919" "9919" "9919" "9919"]]}
{:expected false :arguments [["abc" "abc" "abb" "abc"]]}
{:expected true :arguments [["@" "@" "@" "@"]]}])

(defn solution [elements]
(let [first-elem (first elements)
filtered (filter #(= first-elem %) elements)]
(= (count elements) (count filtered))))
14 changes: 14 additions & 0 deletions test/battle_asserts/issues/jackpot_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(ns battle-asserts.issues.jackpot-test
(:require [clojure.test :refer :all]
[clojure.test.check.properties :as prop]
[clojure.test.check.clojure-test :as ct]
[test-helper :as h]
[battle-asserts.issues.jackpot :as issue]))

(ct/defspec spec-solution
20
(prop/for-all [v (issue/arguments-generator)]
(boolean? (apply issue/solution v))))

(deftest test-solution
(h/generate-tests issue/test-data issue/solution))

0 comments on commit 94f6489

Please sign in to comment.