From bf29efecb36f43e1ea0d6b17e7e2c35d521d7f5d Mon Sep 17 00:00:00 2001 From: Chris Ford Date: Wed, 2 Apr 2014 20:39:08 +0100 Subject: [PATCH 1/2] Detect constants. --- src/testgen/core.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/testgen/core.clj b/src/testgen/core.clj index ebd0357..dc442a6 100644 --- a/src/testgen/core.clj +++ b/src/testgen/core.clj @@ -5,5 +5,13 @@ (list 'is (list '= (list fnname arg) (eval (list fnname arg)))) (catch Exception e (list 'is (list 'thrown? (.getClass e) (list fnname arg)))))) - (defn testgen [fndef] nil) + +(defn is-constant? [x] (not (symbol? x))) + +(defn constants [form] + (filter is-constant? (flatten form))) + +(comment + (constants '(fn is-four [x] (= 88 [44]))) + ) From d5f5b90ab8ea3246df1f05c59340e3c6cda99c08 Mon Sep 17 00:00:00 2001 From: Chris Ford Date: Wed, 2 Apr 2014 21:01:24 +0100 Subject: [PATCH 2/2] Generate tests using detected constants and write-test. --- src/testgen/core.clj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/testgen/core.clj b/src/testgen/core.clj index dc442a6..6716a7a 100644 --- a/src/testgen/core.clj +++ b/src/testgen/core.clj @@ -7,11 +7,15 @@ (defn testgen [fndef] nil) -(defn is-constant? [x] (not (symbol? x))) +(defn constant? [x] (not (symbol? x))) (defn constants [form] - (filter is-constant? (flatten form))) + (filter constant? (flatten form))) + +(defn gen-tests [fnname form] + (map (partial write-test fnname) (constants form))) (comment - (constants '(fn is-four [x] (= 88 [44]))) + (def is-four (fn is-four [x] (= 88 [44]))) + (gen-tests 'is-four '(fn is-four [x] (= 88 [44]))) )