-
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.
Merge pull request #308 from justCxx/htdp/two-trains
Add two trains meet problem
- Loading branch information
Showing
2 changed files
with
37 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,23 @@ | ||
(ns battle-asserts.issues.two-trains-meet | ||
(:require [clojure.test.check.generators :as gen])) | ||
|
||
(def level :elementary) | ||
|
||
(def description "Compute how long after their deparature two trains will meet. | ||
Assume that the trains travel between two points, along a single | ||
section of track, going in opposite directions. The function should | ||
consume the trains' speeds and the starting distance between the trains.") | ||
|
||
(defn arguments-generator [] | ||
(gen/tuple (gen/such-that pos? gen/nat) | ||
(gen/such-that pos? gen/nat) | ||
gen/pos-int)) | ||
|
||
(def test-data | ||
[{:expected 1 :arguments [50 50 100]} | ||
{:expected 4/3 :arguments [25 50 100]}]) | ||
|
||
(defn solution | ||
[v-train1 v-train2 distance] | ||
(/ distance (+ v-train1 | ||
v-train2))) |
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.two-trains-meet-test | ||
(:require [battle-asserts.issues.two-trains-meet :as issue] | ||
[clojure.test :refer :all] | ||
[clojure.test.check.clojure-test :as ct] | ||
[clojure.test.check.properties :as prop] | ||
[test-helper :as h])) | ||
|
||
(ct/defspec spec-solution | ||
20 | ||
(prop/for-all [v (issue/arguments-generator)] | ||
(number? (apply issue/solution v)))) | ||
|
||
(deftest test-solution | ||
(h/generate-tests issue/test-data issue/solution)) |