555f4470bf64

Add test harness
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 20 Mar 2017 15:24:02 +0000
parents 5d2375b8ba78
children a4f701ecf78c
branches/tags (none)
files Makefile cl-pcg.asd cl-pcg.test.asd package.test.lisp test/run.lisp test/tests.lisp vendor/make-quickutils.lisp vendor/quickutils.lisp

Changes

--- a/Makefile	Thu Mar 16 23:28:51 2017 +0000
+++ b/Makefile	Mon Mar 20 15:24:02 2017 +0000
@@ -1,4 +1,4 @@
-.PHONY: vendor pubdocs
+.PHONY: vendor test test-sbcl test-ccl test-ecl test-abcl pubdocs
 
 sourcefiles = $(shell ffind --full-path --literal .lisp)
 docfiles = $(shell ls docs/*.markdown)
@@ -31,3 +31,22 @@
 
 build/pcg: $(lisps)
 	ros build build/pcg.ros
+
+# Testing ---------------------------------------------------------------------
+test: test-sbcl test-ccl test-ecl test-abcl
+
+test-sbcl:
+	echo; figlet -kf computer 'SBCL' | sed -Ee 's/ +$$//' | tr -s '\n' | lolcat --freq=0.25; echo
+	ros run -L sbcl --load test/run.lisp
+
+test-ccl:
+	echo; figlet -kf slant 'CCL' | sed -Ee 's/ +$$//' | tr -s '\n' | lolcat --freq=0.25; echo
+	ros run -L ccl-bin --load test/run.lisp
+
+test-ecl:
+	echo; figlet -kf roman 'ECL' | sed -Ee 's/ +$$//' | tr -s '\n' | lolcat --freq=0.25; echo
+	ros run -L ecl --load test/run.lisp
+
+test-abcl:
+	echo; figlet -kf broadway 'ABCL' | sed -Ee 's/ +$$//' | tr -s '\n' | lolcat --freq=0.25; echo
+	abcl --load test/run.lisp
--- a/cl-pcg.asd	Thu Mar 16 23:28:51 2017 +0000
+++ b/cl-pcg.asd	Mon Mar 20 15:24:02 2017 +0000
@@ -8,6 +8,8 @@
 
   :depends-on (#+sbcl :sb-rotate-byte)
 
+  :in-order-to ((asdf:test-op (asdf:test-op :cl-pcg.test)))
+
   :serial t
   :components ((:module "vendor" :serial t
                 :components ((:file "quickutils-package")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cl-pcg.test.asd	Mon Mar 20 15:24:02 2017 +0000
@@ -0,0 +1,17 @@
+(asdf:defsystem :cl-pcg.test
+  :description "Test suite for cl-pcg"
+
+  :author "Steve Losh <steve@stevelosh.com>"
+  :license "MIT"
+
+  :depends-on (:cl-pcg :1am)
+
+  :serial t
+  :components ((:file "package.test")
+               (:module "test"
+                :serial t
+                :components ((:file "tests"))))
+
+  :perform (asdf:test-op
+             (op system)
+             (uiop:symbol-call :pcg.test :run-tests)))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package.test.lisp	Mon Mar 20 15:24:02 2017 +0000
@@ -0,0 +1,8 @@
+(defpackage :pcg.test
+  (:use
+    :cl
+    :1am
+    :pcg
+    :pcg.quickutils)
+  (:export
+    :run-tests))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/run.lisp	Mon Mar 20 15:24:02 2017 +0000
@@ -0,0 +1,5 @@
+#+ecl (setf compiler:*user-cc-flags* "-Wno-shift-negative-value")
+
+(ql:quickload 'cl-pcg)
+(time (asdf:test-system 'cl-pcg))
+(quit)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tests.lisp	Mon Mar 20 15:24:02 2017 +0000
@@ -0,0 +1,31 @@
+(in-package :pcg.test)
+
+
+;;;; Utils --------------------------------------------------------------------
+(defmacro define-test (name &body body)
+  `(test ,(symb 'test- name)
+    (let ((*package* ,*package*))
+      ,@body)))
+
+(defmacro gimme (n &body body)
+  `(loop :repeat ,n :collect (progn ,@body)))
+
+
+(defun run-tests ()
+  (1am:run))
+
+
+;;;; Tests --------------------------------------------------------------------
+(define-test rewind
+  (let ((g (make-pcg))
+        (a nil)
+        (b nil))
+    (setf a (gimme 20 (pcg-random g 50000)))
+    (pcg-rewind g 20) ; Rewind to start
+    (setf b (gimme 20 (pcg-random g 50000)))
+    (is (equal a b))
+    (setf a (gimme 10 (pcg-random g 50000)))
+    (pcg-rewind g 10) ; Rewind back to midpoint
+    (setf b (gimme 10 (pcg-random g 50000)))
+    (is (equal a b))
+    ))
--- a/vendor/make-quickutils.lisp	Thu Mar 16 23:28:51 2017 +0000
+++ b/vendor/make-quickutils.lisp	Mon Mar 20 15:24:02 2017 +0000
@@ -4,6 +4,7 @@
   "quickutils.lisp"
   :utilities '(
 
+               :symb
 
                )
   :package "PCG.QUICKUTILS")
--- a/vendor/quickutils.lisp	Thu Mar 16 23:28:51 2017 +0000
+++ b/vendor/quickutils.lisp	Mon Mar 20 15:24:02 2017 +0000
@@ -2,7 +2,7 @@
 ;;;; See http://quickutil.org for details.
 
 ;;;; To regenerate:
-;;;; (qtlc:save-utils-as "quickutils.lisp" :ensure-package T :package "PCG.QUICKUTILS")
+;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:SYMB) :ensure-package T :package "PCG.QUICKUTILS")
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (unless (find-package "PCG.QUICKUTILS")
@@ -12,6 +12,26 @@
 
 (in-package "PCG.QUICKUTILS")
 
-NIL
+(when (boundp '*utilities*)
+  (setf *utilities* (union *utilities* '(:MKSTR :SYMB))))
+
+  (defun mkstr (&rest args)
+    "Receives any number of objects (string, symbol, keyword, char, number), extracts all printed representations, and concatenates them all into one string.
+
+Extracted from _On Lisp_, chapter 4."
+    (with-output-to-string (s)
+      (dolist (a args) (princ a s))))
+  
+
+  (defun symb (&rest args)
+    "Receives any number of objects, concatenates all into one string with `#'mkstr` and converts them to symbol.
+
+Extracted from _On Lisp_, chapter 4.
+
+See also: `symbolicate`"
+    (values (intern (apply #'mkstr args))))
+  
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (export '(symb)))
 
 ;;;; END OF quickutils.lisp ;;;;