-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add solution for jackpot task (#512)
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |