summaryrefslogtreecommitdiff
path: root/test/LatticeTest.hs
blob: 403c6507a7e9ae217920e2f5305570737bddc3d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module LatticeTest (suite) where

import Test.Tasty
import Test.Tasty.HUnit
import World.Lattice 

suite :: TestTree
suite = testGroup "lattice tests" $
  [ latticeGrowth
  ]


data GrowKind = Empty | Plant deriving (Show, Enum, Eq)
data GrowFlags = None deriving (Show, Eq)


latticeGrowth :: TestTree
latticeGrowth = testCase "growth update rule" $
  let
    plant = LatticeCell Plant None
    empty = LatticeCell Empty None
    lattice = [[ empty, empty, plant ]]
    rules =
      [ 
        -- empty
        \l x y -> 
          if kind ((l !! y) !! (x+1)) == Plant
          then LatticeCell Plant None
          else LatticeCell Empty None
        -- plant
        , \_ _ _ -> LatticeCell Plant None
      ] :: [LatticeRule GrowKind GrowFlags]
    lattice' = updateLattice lattice rules
    lattice'' = updateLattice lattice' rules
  in do
    lattice' @?= [[ empty, plant, plant ]]
    lattice'' @?= [[ plant, plant, plant ]]