Permalink
Browse files

check generators are repeatable, fix seed, shuffle, stop test on inpu…

…t failure
  • Loading branch information...
1 parent 992d301 commit 4d488b9c56dc149d2a188e9c906c3efd4aa2a399 @stuarthalloway stuarthalloway committed Aug 15, 2012
@@ -47,10 +47,12 @@
(defmacro fail
[& args]
- (with-meta `(event/report-context :type ::fail
- :level :warn
- ~@args)
- (meta &form)))
+ `(do
+ (runner/failed!)
+ ~(with-meta `(event/report-context :type ::fail
+ :level :warn
+ ~@args)
+ (meta &form))))
(defmacro is
([v] (with-meta `(is ~v nil) (meta &form)))
@@ -17,7 +17,7 @@ cases, because
1. Spec compilation uses these fns for you automatically.
2. There are lot of collisions with clojure.core!"}
clojure.test.generative.generators
- (:refer-clojure :exclude [byte char long int short float double boolean string symbol keyword list vec set hash-map name rand-nth byte-array boolean-array short-array char-array int-array long-array float-array double-array])
+ (:refer-clojure :exclude [byte char long int short float double boolean string symbol keyword list vec set hash-map name rand-nth byte-array boolean-array short-array char-array int-array long-array float-array double-array shuffle])
(:require [clojure.core :as core]))
(def ^:dynamic ^java.util.Random
@@ -274,6 +274,12 @@ instance you can get a repeatable basis for tests."
[]
(one-of scalar collection))
+(defn shuffle
+ "Shuffle coll"
+ [coll]
+ (sort-by double coll))
+
+
@@ -63,7 +63,8 @@
(map
#(future
(try
- (binding [gen/*seed* (java.util.Random. (+ % 42))
+ (binding [gen/*seed* (+ % 42)
+ gen/*rnd* (java.util.Random. gen/*seed*)
*failed* (promise)]
(loop [iter 0]
(let [result (run-iter test)
@@ -0,0 +1,15 @@
+(ns clojure.test.generative.generators-test
+ (:use clojure.test.generative)
+ (:require [clojure.test.generative.generators :as gen]))
+
+(defspec test-repeatable-generation
+ (constantly nil)
+ [^int seed ^{:tag (uniform 1 100)} iters]
+ (let [generator (fn []
+ (binding [gen/*rnd* (java.util.Random. seed)]
+ (into [] (repeatedly iters gen/anything))))
+ gen-1 (generator)
+ gen-2 (generator)]
+ (dotimes [iter iters]
+ (is (= (nth gen-1 iter)
+ (nth gen-2 iter))))))

0 comments on commit 4d488b9

Please sign in to comment.