Skip to content

Commit

Permalink
Merge pull request #308 from justCxx/htdp/two-trains
Browse files Browse the repository at this point in the history
Add two trains meet problem
  • Loading branch information
mokevnin committed Dec 27, 2015
2 parents cc0419a + 23ca77e commit 4c8a523
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/battle_asserts/issues/two_trains_meet.clj
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)))
14 changes: 14 additions & 0 deletions test/battle_asserts/issues/two_trains_meet_test.clj
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))

0 comments on commit 4c8a523

Please sign in to comment.