random: add regression tests
authorDaniel Kochmański <daniel@turtleware.eu>
Mon, 21 Sep 2015 17:14:20 +0000 (19:14 +0200)
committerDaniel Kochmański <daniel@turtleware.eu>
Mon, 21 Sep 2015 17:14:20 +0000 (19:14 +0200)
Signed-off-by: Daniel Kochmański <daniel@turtleware.eu>
src/tests/regressions/tests/random-states.lsp [new file with mode: 0644]

diff --git a/src/tests/regressions/tests/random-states.lsp b/src/tests/regressions/tests/random-states.lsp
new file mode 100644 (file)
index 0000000..aa550f8
--- /dev/null
@@ -0,0 +1,55 @@
+;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil -*-
+;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
+
+;;;; Author:   Daniel Kochmański
+;;;; Created:  2015-09-21
+;;;; Contains: Random state tests
+
+(in-package :cl-test)
+
+;; Trivial case
+(deftest random-states.0001
+    (numberp (random 18))
+  T)
+
+;; Check if we can generate random number from a read random state
+(deftest random-states.0002
+    (numberp (random 18 #$1))
+  T)
+
+;; Check if we can generate random number from a new random state
+(deftest random-states.0003
+    (numberp (random 18 (make-random-state)))
+  T)
+
+;; Check if we can copy use copied random state from reader
+(deftest random-states.0004
+    (numberp (random 18 (make-random-state #$1)))
+  T)
+
+;; Check if the same seed produces the same result
+(deftest random-states.0005
+    (= (random 18 #$1)
+       (random 18 #$1)
+       (random 18 #$1))
+  T)
+
+;; Check if we get the same table from the same seed
+(deftest random-states.0005
+    (let ((*print-readably* t)
+          (rs (make-random-state #$1)))
+      (equalp
+       (format nil "~S" #$1)
+       (format nil "~S" rs)))
+  T)
+
+;; Check if we can read back the random state
+(deftest random-states.0006
+    (let* ((*print-readably* t)
+           (rs (make-random-state #$1))
+           (rs-read (read-from-string
+                     (format nil "~S" rs))))
+      (equalp
+       (format nil "~S" rs-read)
+       (format nil "~S" rs)))
+  T)