From 5498e7bc767d39ba368d18074afc5f488088dc20 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 18 Apr 2012 23:50:16 +0200 Subject: [PATCH] Tests for scripting PRNG. --- tests/unit/scripting.tcl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index 009c1347d..ed58bca44 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -251,6 +251,26 @@ start_server {tags {"scripting"}} { lappend res [r eval $decr_if_gt 1 foo 2] set res } {4 3 2 2 2} + + test {Scripting engine resets PRNG at every script execution} { + set rand1 [r eval {return tostring(math.random())} 0] + set rand2 [r eval {return tostring(math.random())} 0] + assert_equal $rand1 $rand2 + } + + test {Scripting engine PRNG can be seeded correctly} { + set rand1 [r eval { + math.randomseed(ARGV[1]); return tostring(math.random()) + } 0 10] + set rand2 [r eval { + math.randomseed(ARGV[1]); return tostring(math.random()) + } 0 10] + set rand3 [r eval { + math.randomseed(ARGV[1]); return tostring(math.random()) + } 0 20] + assert_equal $rand1 $rand2 + assert {$rand2 ne $rand3} + } } start_server {tags {"scripting repl"}} {