-
Notifications
You must be signed in to change notification settings - Fork 68
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 farm problem issue (#464)
- Loading branch information
Showing
2 changed files
with
48 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,33 @@ | ||
(ns battle-asserts.issues.farm-problem | ||
(:require [clojure.test.check.generators :as gen])) | ||
|
||
(def level :elementary) | ||
|
||
(def description "A farmer is asking you to tell him how many legs can be counted among all his animals. | ||
The farmer breeds three species: | ||
`chickens = 2 legs` | ||
`cows = 4 legs` | ||
`pigs = 4 legs` | ||
The farmer has counted his animals and he gives you a subtotal for each species. | ||
You have to implement a function that returns the total number of legs of all the animals.") | ||
|
||
(def signature | ||
{:input [{:argument-name "chickens" :type {:name "integer"}} | ||
{:argument-name "cows" :type {:name "integer"}} | ||
{:argument-name "pigs" :type {:name "integer"}}] | ||
:output {:type {:name "integer"}}}) | ||
|
||
(defn arguments-generator | ||
[] | ||
(gen/tuple gen/small-integer | ||
gen/small-integer | ||
gen/small-integer)) | ||
|
||
(def test-data | ||
[{:expected 36 :arguments [2 3 5]} | ||
{:expected 22 :arguments [1 2 3]} | ||
{:expected 50 :arguments [5 2 8]}]) | ||
|
||
(defn solution | ||
[chickens cows pigs] | ||
(+ (* chickens 2) (* cows 4) (* pigs 4))) |
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,15 @@ | ||
(ns battle-asserts.issues.farm-problem-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.farm-problem :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)) | ||
|