Generated tests in a dogfood stylee, and added them. They succeed!
This commit is contained in:
parent
f80627763c
commit
75a35a5043
|
@ -2,7 +2,7 @@
|
|||
|
||||
(defn write-test [fnname arg]
|
||||
(try
|
||||
(list 'is (list '= (list fnname arg) (eval (list fnname arg))))
|
||||
(list 'is (list '= (list fnname arg) (list 'quote (eval (list fnname arg)))))
|
||||
(catch Exception e (list 'is (list 'thrown? (.getClass e) (list fnname arg))))))
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
|||
(vector? arg)
|
||||
(map? arg))))
|
||||
|
||||
(def generic-args '(nil () true "test" :test 0 Integer/MAX_VALUE 0.0001 -0.0001))
|
||||
(def generic-args '(nil () (quote (a :b "c")) true "test" :test 0 Integer/MAX_VALUE 22/7 0.0001 -0.0001))
|
||||
|
||||
(defn constants [form]
|
||||
"return a list of all elements in this form which are constants"
|
||||
|
@ -25,14 +25,15 @@
|
|||
(flatten
|
||||
(map
|
||||
#(cond
|
||||
(number? %) (list % (inc %) (dec %))
|
||||
(integer? %) (list % (inc %) (dec %))
|
||||
(number? %) (list % (+ % 0.0001) (- % 0.0001))
|
||||
true %)
|
||||
(constants sexpr)))))
|
||||
|
||||
(defn testgen [fndef]
|
||||
(cond (= (first fndef) 'defn)
|
||||
(let [name (first (rest fndef))]
|
||||
(list 'deftest (symbol (str "test-" name))
|
||||
(concat (list 'deftest (symbol (str "test-" name)))
|
||||
(map #(write-test name %) (find-interesting-args fndef))))))
|
||||
|
||||
;; (defn gen-tests [fnname form]
|
||||
|
|
|
@ -1,7 +1,77 @@
|
|||
(ns testgen.core-test
|
||||
"In the spirit of eating your own dogfood, all these tests are generated
|
||||
with testgen."
|
||||
(:require [clojure.test :refer :all]
|
||||
[testgen.core :refer :all]))
|
||||
|
||||
(deftest a-test
|
||||
(testing "FIXME, I fail."
|
||||
(is (= 0 1))))
|
||||
|
||||
|
||||
(deftest
|
||||
test-integer?
|
||||
(is (= (integer? nil) false))
|
||||
(is (= (integer? ()) false))
|
||||
(is (= (integer? '(a :b "c")) false))
|
||||
(is (= (integer? true) false))
|
||||
(is (= (integer? "test") false))
|
||||
(is (= (integer? :test) false))
|
||||
(is (= (integer? 0) true))
|
||||
(is (= (integer? Integer/MAX_VALUE) true))
|
||||
(is (= (integer? 22/7) false))
|
||||
(is (= (integer? 1.0E-4) false))
|
||||
(is (= (integer? -1.0E-4) false))
|
||||
(is (= (integer? "Returns true if n is an integer") false)))
|
||||
|
||||
|
||||
(deftest
|
||||
test-testgen
|
||||
(is (= (testgen nil) nil))
|
||||
(is (= (testgen ()) nil))
|
||||
(is (= (testgen '(a :b "c")) nil))
|
||||
(is (thrown? java.lang.IllegalArgumentException (testgen true)))
|
||||
(is (= (testgen "test") nil))
|
||||
(is (thrown? java.lang.IllegalArgumentException (testgen :test)))
|
||||
(is (thrown? java.lang.IllegalArgumentException (testgen 0)))
|
||||
(is
|
||||
(thrown?
|
||||
java.lang.IllegalArgumentException
|
||||
(testgen Integer/MAX_VALUE)))
|
||||
(is (thrown? java.lang.IllegalArgumentException (testgen 22/7)))
|
||||
(is (thrown? java.lang.IllegalArgumentException (testgen 1.0E-4)))
|
||||
(is (thrown? java.lang.IllegalArgumentException (testgen -1.0E-4)))
|
||||
(is (= (testgen "test-") nil)))
|
||||
|
||||
(deftest
|
||||
test-constant?
|
||||
(is (= (constant? nil) 'true))
|
||||
(is (= (constant? ()) 'false))
|
||||
(is (= (constant? '(a :b "c")) 'false))
|
||||
(is (= (constant? true) 'true))
|
||||
(is (= (constant? "test") 'true))
|
||||
(is (= (constant? :test) 'true))
|
||||
(is (= (constant? 0) 'true))
|
||||
(is (= (constant? Integer/MAX_VALUE) 'true))
|
||||
(is (= (constant? 22/7) 'true))
|
||||
(is (= (constant? 1.0E-4) 'true))
|
||||
(is (= (constant? -1.0E-4) 'true)))
|
||||
|
||||
(deftest
|
||||
test-constants
|
||||
(is (= (constants nil) '()))
|
||||
(is (= (constants ()) '()))
|
||||
(is (= (constants '(a :b "c")) '(:b "c")))
|
||||
(is (= (constants true) '()))
|
||||
(is (= (constants "test") '()))
|
||||
(is (= (constants :test) '()))
|
||||
(is (= (constants 0) '()))
|
||||
(is (= (constants Integer/MAX_VALUE) '()))
|
||||
(is (= (constants 22/7) '()))
|
||||
(is (= (constants 1.0E-4) '()))
|
||||
(is (= (constants -1.0E-4) '()))
|
||||
(is
|
||||
(=
|
||||
(constants
|
||||
"return a list of all elements in this form which are constants")
|
||||
'())))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue