From 6af03289e5285cae77aaef9f5f1a1d4ca4e68510 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Wed, 2 Apr 2014 21:17:01 +0100 Subject: [PATCH] Generating some reasonably interesting arguments --- src/testgen/core.clj | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/testgen/core.clj b/src/testgen/core.clj index ebd0357..005c7b3 100644 --- a/src/testgen/core.clj +++ b/src/testgen/core.clj @@ -5,5 +5,32 @@ (list 'is (list '= (list fnname arg) (eval (list fnname arg)))) (catch Exception e (list 'is (list 'thrown? (.getClass e) (list fnname arg)))))) +(defn constant? [arg] + (not (or + (symbol? arg) + (seq? arg) + (vector? arg) + (map? arg)))) + +(def generic-args nil () true "test" :test 0 Integer/MAX_VALUE 0.0001 -0.0001) + +(defn find-interesting-args [sexpr] + "Find things in sexpr which would be interesting if passed as arguments to it" + (filter constant? (flatten sexpr))) + +(defn find-more-interesting-args [sexpr] + "Find things in sexpr which would be even more interesting if passed as arguments to it" + (concat generic-args + (flatten + (map + #(cond + (number? %) (list % (inc %) (dec %)) + true %) + (find-interesting-args sexpr)))) + +(defn testgen [fndef] + (cond (= (first fndef) 'defn) + (let [name (first (rest fndef))] + (list 'deftest (symbol (str "test-" name)) + (map #(write-test name %) (find-more-interesting-args fndef)))))) -(defn testgen [fndef] nil)