Skip to content
Snippets Groups Projects
Commit c62e3467 authored by Raymond Toy's avatar Raymond Toy
Browse files

Add tests for xoroshiro generator

parent 192fe3b6
No related branches found
No related tags found
No related merge requests found
;; Tests for RNG
(defpackage :rng-tests
(:use :cl :lisp-unit))
(in-package "RNG-TESTS")
(defun 64-bit-rng-state (rng)
(let ((state (kernel::xoro-random-state-state rng)))
(flet ((convert (x)
(multiple-value-bind (hi lo)
(kernel:double-float-bits x)
(logior (ash (ldb (byte 32 0) hi) 32)
lo))))
(values (convert (aref state 0)) (convert (aref state 1))))))
(defun 64-bit-value (rng)
(logior (ash (kernel::xoroshiro-chunk rng) 32)
(kernel::xoroshiro-chunk rng)))
(defvar *test-state*)
(define-test rng.initial-state
(setf *test-state*
(kernel::make-xoroshiro-object :state (kernel::init-xoro-state #x12345678)
:rand 0
:cached-p nil))
(multiple-value-bind (s0 s1)
(64-bit-rng-state *test-state*)
(assert-equal #x38f1dc39d1906b6f s0)
(assert-equal #xdfe4142236dd9517 s1)
(assert-equal 0 (kernel::xoro-random-state-rand *test-state*))
(assert-equal nil (kernel::xoro-random-state-cached-p *test-state*))))
(define-test rng.values-test
(assert-equal (list #x38f1dc39d1906b6f #xdfe4142236dd9517)
(multiple-value-list (64-bit-rng-state *test-state*)))
(assert-equal 0 (kernel::xoro-random-state-rand *test-state*))
(assert-equal nil (kernel::xoro-random-state-cached-p *test-state*))
(dolist (item '((#x18d5f05c086e0086 (#x228f4926843b364d #x74dfe78e715c81be))
(#x976f30b4f597b80b (#x5b6bd4558bd96a68 #x567b7f35650aea8f))
(#xb1e7538af0e454f7 (#x13e5253e242fac52 #xed380e70d10ab60e))
(#x011d33aef53a6260 (#x9d0764952ca00d8a #x5251a5cfedd2b4ef))
(#xef590a651a72c279 (#xba4ef2b425bda963 #x172b965cf56c15ac))
(#xd17a89111b29bf0f (#x458277a5e5f0a21b #xd1bccfad6564e8d))
(#x529e44a0bc46f0a8 (#x2becb68d5a7194c7 #x3a6ec964899bb5f3))
(#x665b7ff1e40d4aba (#xededfd481d0a19fe #x3ea213411827fe9d))
(#x2c9010893532189b (#xd7bb59bcd8fba26f #x52de763d34fee090))
(#x2a99cffa0dfa82ff (#xf96e892c62d6ff2e #xc0542ff85652f81e))))
(destructuring-bind (value state)
item
(assert-equal value (64-bit-value *test-state*))
(assert-equal state (multiple-value-list (64-bit-rng-state *test-state*))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment