about summary refs log tree commit diff
path: root/test/Xanthous
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-09-10T00·54-0400
committerGriffin Smith <root@gws.fyi>2019-09-10T00·54-0400
commit9ebdc6fbb446fea5e505172a6b3dd459beaf3552 (patch)
treea1403026afb597e12c25e84ef8991f062655e5b8 /test/Xanthous
parente01cf9b0565eaa9c09e19f66331a2010aea908cb (diff)
Convert generated levels to walls
Add support for converting generated levels to walls, and merge one into
the entity map at the beginning of the game.

There's nothing here that guarantees the character ends up *inside* the
level though (they almost always don't) so that'll have to be slotted
into the level generation process.
Diffstat (limited to 'test/Xanthous')
-rw-r--r--test/Xanthous/GameSpec.hs2
-rw-r--r--test/Xanthous/Generators/UtilSpec.hs13
2 files changed, 13 insertions, 2 deletions
diff --git a/test/Xanthous/GameSpec.hs b/test/Xanthous/GameSpec.hs
index 9319399ac2..dbd1677f7e 100644
--- a/test/Xanthous/GameSpec.hs
+++ b/test/Xanthous/GameSpec.hs
@@ -5,7 +5,7 @@ import Xanthous.Game
 import Control.Lens.Properties
 import Xanthous.Data (move, Direction(Down))
 import Xanthous.Data.EntityMap (atPosition)
-import Xanthous.Entities.SomeEntity
+import Xanthous.Entities (SomeEntity(SomeEntity))
 
 main :: IO ()
 main = defaultMain test
diff --git a/test/Xanthous/Generators/UtilSpec.hs b/test/Xanthous/Generators/UtilSpec.hs
index a1c2f79d60..c82c385987 100644
--- a/test/Xanthous/Generators/UtilSpec.hs
+++ b/test/Xanthous/Generators/UtilSpec.hs
@@ -41,7 +41,7 @@ test = testGroup "Xanthous.Generators.Util"
                 $ randInitialize dims aliveChance
         in bounds res === ((0, 0), (dims ^. width, dims ^. height))
     ]
-  , testGroup "numAliveNeighbors"
+  , testGroup "numAliveNeighborsM"
     [ testProperty "maxes out at 8" $ \(GenArray (arr :: Array (Word, Word) Bool)) loc ->
         let
           act :: forall s. ST s Word
@@ -51,6 +51,17 @@ test = testGroup "Xanthous.Generators.Util"
           res = runST act
         in counterexample (show res) $ between 0 8 res
     ]
+  , testGroup "numAliveNeighbors"
+    [ testProperty "is equivalient to runST . numAliveNeighborsM . thaw" $
+      \(GenArray (arr :: Array (Word, Word) Bool)) loc ->
+        let
+          act :: forall s. ST s Word
+          act = do
+            mArr <- thaw @_ @_ @_ @(STUArray s) arr
+            numAliveNeighborsM mArr loc
+          res = runST act
+        in numAliveNeighbors arr loc === res
+    ]
   , testGroup "cloneMArray"
       [ testCase "clones the array" $ runST $
           let