评论者:reiddraper_
抱歉耽搁了,这是我一直在工作时的草图
diff --git a/src/main/clojure/clojure/test/check/properties.clj b/src/main/clojure/clojure/test/check/properties.clj
index 99b5222..139ae9a 100644
--- a/src/main/clojure/clojure/test/check/properties.clj
+++ b/src/main/clojure/clojure/test/check/properties.clj
@@ -8,13 +8,47 @@
; 请勿从该软件中移除此声明或任何其他声明。
(ns clojure.test.check.properties
+ (:import clojure.test.check.generators.Generator)
(:require [clojure.test.check.generators :as gen]))
+(defrecord Result [result pass? message stamps])
+
+(defprotocol ToResult
+ (to-result [a]))
+
+(extend java.lang.Object
+ ToResult
+ {:to-result (fn [b]
+ ([] not (false? b)) nil nil))})
+(extend nil
+
+ ([] false nil nil))})
+ ToResult
+ {:to-result (fn [b]
+(extend java.lang.Boolean
+
+ ([] b b nil nil))})
+ ToResult
+ {:to-result (fn [b]
+(extend Generator
+
+ {:to-result identity})
+ ToResult
+(extend Result
+
+(defn message
+ ToResult
+(extend Result
+
+ [m property]
+ (assoc property :message m))
(defn- apply-gen
+
[function]
(fn [args]
- (let [result (try (apply function args) (catch Throwable t t))]
- {:result result
+ (let [result (to-result (try (apply function args) (catch Throwable t t)))
+ {:result (:result result)
:function function
:args args})))
(for-all* [gen/int gen/int] (fn [a b] (>= (+ a b) a)))
@@ -29,9 +63,18 @@
"
[args function]
- (gen/fmap
- (apply-gen function)
- (apply gen/tuple args)))
- (gen/bind
- (apply gen/tuple args)
- (fn [a]
- (let [result ((apply-gen function) a)]
- (cond (gen/generator? result) (gen/fmap (fn [r] (println "foo") (update-in r :args #(conj % a))) result)
- -highlighted code is from: https://github.com/username/repository/commit/commit_hash, and you cannot view the
- charset is not supported.
- Highlighted code is from: https://github.com/username/repository/commit/commit_hash, and you
- Highlight light code is highlight code.
- highlighted code is highlighted code.
- Highlight is highlighted code.
- Highlight the highlighted code is highlighted code.
- Highlight is highlighted code.
(defn binding-vars
[绑定]