d8bd8e7eea
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
29 lines
1.1 KiB
Haskell
29 lines
1.1 KiB
Haskell
--------------------------------------------------------------------------------
|
|
module Xanthous.Game.StateSpec (main, test) where
|
|
--------------------------------------------------------------------------------
|
|
import Test.Prelude
|
|
--------------------------------------------------------------------------------
|
|
import Xanthous.Game.State
|
|
import Xanthous.Entities.Raws (raws, entityFromRaw)
|
|
import Control.Monad.Random (evalRandT)
|
|
import System.Random (getStdGen)
|
|
--------------------------------------------------------------------------------
|
|
|
|
main :: IO ()
|
|
main = defaultMain test
|
|
|
|
test :: TestTree
|
|
test = testGroup "Xanthous.Game.StateSpec"
|
|
[ testGroup "entityTypeName"
|
|
[ testCase "for a creature" $ do
|
|
let gormlakRaw = raws ^?! ix "gormlak"
|
|
creature <- runRand $ entityFromRaw gormlakRaw
|
|
entityTypeName creature @?= "Creature"
|
|
, testCase "for an item" $ do
|
|
let stickRaw = raws ^?! ix "stick"
|
|
item <- runRand $ entityFromRaw stickRaw
|
|
entityTypeName item @?= "Item"
|
|
]
|
|
]
|
|
where
|
|
runRand x = evalRandT x =<< getStdGen
|