From d8bd8e7eea5dcef4901bee14b8fe3027fd8605ac Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 19 Jun 2021 11:49:20 -0400 Subject: feat(xanthous) Generate random volume+density for items 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 Tested-by: BuildkiteCI --- users/grfn/xanthous/test/Xanthous/Game/StateSpec.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'users/grfn/xanthous/test') 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 -- cgit 1.4.1