From c9cb50b34b141ab08c4f5f95a15e0242bc750a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Buckwalter?= Date: Sat, 17 Sep 2011 11:03:29 +0800 Subject: [PATCH] Spec for "reasonably random" appearance. --- yesod-core/test/Test/InternalRequest.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/yesod-core/test/Test/InternalRequest.hs b/yesod-core/test/Test/InternalRequest.hs index c48df2e1..ba510cb5 100644 --- a/yesod-core/test/Test/InternalRequest.hs +++ b/yesod-core/test/Test/InternalRequest.hs @@ -12,9 +12,14 @@ import Test.Hspec randomStringSpecs :: [Spec] randomStringSpecs = describe "Yesod.Internal.Request.randomString" - [ it "does not repeat itself" $ noRepeat 10 100 + [ it "looks reasonably random" looksRandom + , it "does not repeat itself" $ noRepeat 10 100 ] +-- NOTE: this testcase may break on other systems/architectures if +-- mkStdGen is not identical everywhere (is it?). +looksRandom = randomString 20 (mkStdGen 0) == "VH9SkhtptqPs6GqtofVg" + noRepeat len n = length (nub $ map (randomString len . mkStdGen) [1..n]) == n