about summary refs log tree commit diff
path: root/users/grfn/xanthous/test
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-06-19T15·49-0400
committergrfn <grfn@gws.fyi>2021-06-23T21·52+0000
commitd8bd8e7eea5dcef4901bee14b8fe3027fd8605ac (patch)
tree0b9e02b87175ff8d16baa5a7d8a1c60a267cea28 /users/grfn/xanthous/test
parent8b97683f6ef53605130542ea6de1e587b353aa5b (diff)
feat(xanthous) Generate random volume+density for items r/2679
Generate random volumes and densities for items based on the ranges for
those two quantities in the raw when building instances of items.

Since this is the first time creating an item is impure, this also lifts
entity generation into a (random) monadic context

Change-Id: I2de4880e8144f7ff9e1304eb32806ed1d7affa18
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3226
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/grfn/xanthous/test')
-rw-r--r--users/grfn/xanthous/test/Xanthous/Game/StateSpec.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/users/grfn/xanthous/test/Xanthous/Game/StateSpec.hs b/users/grfn/xanthous/test/Xanthous/Game/StateSpec.hs
index 3267d8ef9e9c..b02abb04b49c 100644
--- a/users/grfn/xanthous/test/Xanthous/Game/StateSpec.hs
+++ b/users/grfn/xanthous/test/Xanthous/Game/StateSpec.hs
@@ -5,6 +5,8 @@ import           Test.Prelude
 --------------------------------------------------------------------------------
 import           Xanthous.Game.State
 import           Xanthous.Entities.Raws (raws, entityFromRaw)
+import Control.Monad.Random (evalRandT)
+import System.Random (getStdGen)
 --------------------------------------------------------------------------------
 
 main :: IO ()
@@ -13,13 +15,15 @@ main = defaultMain test
 test :: TestTree
 test = testGroup "Xanthous.Game.StateSpec"
   [ testGroup "entityTypeName"
-    [ testCase "for a creature" $
+    [ testCase "for a creature" $ do
         let gormlakRaw = raws ^?! ix "gormlak"
-            creature = entityFromRaw gormlakRaw
-        in entityTypeName creature @?= "Creature"
-    , testCase "for an item" $
+        creature <- runRand $ entityFromRaw gormlakRaw
+        entityTypeName creature @?= "Creature"
+    , testCase "for an item" $ do
         let stickRaw = raws ^?! ix "stick"
-            item = entityFromRaw stickRaw
-        in entityTypeName item @?= "Item"
+        item <- runRand $ entityFromRaw stickRaw
+        entityTypeName item @?= "Item"
     ]
   ]
+  where
+    runRand x = evalRandT x =<< getStdGen