Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add solution for jackpot task #512

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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))