X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=t%2Fexample.lisp;fp=t%2Fexample.lisp;h=fadeafd85e75cdb43bd55f1ed37d3d6129efded6;hb=9adc37ba6fbe512af2c83863e9f51461479678ed;hp=6131c3909668867f35552e3b430b056ab4490565;hpb=b946ea038243212fde4fa87103604a00666ddbf3;p=fiveam.git diff --git a/t/example.lisp b/t/example.lisp index 6131c39..fadeafd 100644 --- a/t/example.lisp +++ b/t/example.lisp @@ -85,3 +85,35 @@ (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 80) + (< split-point (length result)))) + (is (string= result (dummy-strcat (subseq result 0 split-point) + (subseq result split-point)))))) + +(5am:run! 'dummy-strcat) \ No newline at end of file