X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=t%2Fexample.lisp;h=87c89f711d4a8c1a16f1cab405d10da3e9271c73;hb=9181201dc6822a12b605581385091b1591675dc4;hp=6131c3909668867f35552e3b430b056ab4490565;hpb=1454981ac5f4f7ea8fe741a8125efbf0b09497ea;p=fiveam.git diff --git a/t/example.lisp b/t/example.lisp index 6131c39..87c89f7 100644 --- a/t/example.lisp +++ b/t/example.lisp @@ -85,3 +85,38 @@ (is (= 2 (add-2 0))) (is (= 0 (add-2 -2))) (is (= 0 (add-2 0)))) + +;; Finally let's try out the specification based testing. + +(defun dummy-add (a b) + (+ a b)) + +(defun dummy-strcat (a b) + (concatenate 'string a b)) + +(test dummy-add + (for-all ((a (gen-integer)) + (b (gen-integer))) + ;; assuming we have an "oracle" to compare our function results to + ;; we can use it: + (is (= (+ a b) (dummy-add a b))) + ;; if we don't have an oracle (as in most cases) we just ensure + ;; that certain properties hold: + (is (= (dummy-add a b) + (dummy-add b a))) + (is (= a (dummy-add a 0))) + (is (= 0 (dummy-add a (- a)))) + (is (< a (dummy-add a 1))) + (is (= (* 2 a) (dummy-add a a))))) + +(test dummy-strcat + (for-all ((result (gen-string)) + (split-point (gen-integer :min 0 :max 10000) + (< split-point (length result)))) + (is (string= result (dummy-strcat (subseq result 0 split-point) + (subseq result split-point)))))) + +(test random-failure + (for-all ((result (gen-integer :min 0 :max 1))) + (is (plusp result)) + (is (= result 0))))