mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-12 12:21:15 -08:00
random: add regression tests
Signed-off-by: Daniel Kochmański <daniel@turtleware.eu>
This commit is contained in:
parent
68e89cbf97
commit
ccafd2c54e
1 changed files with 55 additions and 0 deletions
55
src/tests/regressions/tests/random-states.lsp
Normal file
55
src/tests/regressions/tests/random-states.lsp
Normal file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue