-
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 greatest common divisor issue (#446)
* Add solution for greatest common divisor issue * Fix typo Co-authored-by: Vitaly <vtmilyakov@yandex.ru>
- Loading branch information
Showing
2 changed files
with
43 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,29 @@ | ||
(ns battle-asserts.issues.greatest-common-divisor | ||
(:require [clojure.test.check.generators :as gen])) | ||
|
||
(def level :easy) | ||
|
||
(def description "Create a function that calculates GCD (Greatest Common Divisor).") | ||
|
||
(def signature | ||
{:input [{:argument-name "x" :type {:name "integer"}} | ||
{:argument-name "y" :type {:name "integer"}}] | ||
:output {:type {:name "integer"}}}) | ||
|
||
(defn arguments-generator [] | ||
(gen/tuple (gen/choose 1 50) (gen/choose 1 50))) | ||
|
||
(def test-data | ||
[{:arguments [8 24] | ||
:expected 8} | ||
{:arguments [8 26] | ||
:expected 2} | ||
{:arguments [42 56] | ||
:expected 14} | ||
{:arguments [15 50] | ||
:expected 5}]) | ||
|
||
(defn solution [x y] | ||
(if (zero? y) | ||
x | ||
(recur y (mod x y)))) |
14 changes: 14 additions & 0 deletions
14
test/battle_asserts/issues/greatest_common_divisor_test.clj
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.greatest-common-divisor-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.greatest-common-divisor :as issue])) | ||
|
||
(ct/defspec spec-solution | ||
20 | ||
(prop/for-all [v (issue/arguments-generator)] | ||
(instance? Number (apply issue/solution v)))) | ||
|
||
(deftest test-solution | ||
(h/generate-tests issue/test-data issue/solution)) |