creatur 5.2.1 → 5.2.3
raw patch · 6 files changed
+114/−66 lines, 6 filesdep ~binarydep ~cerealdep ~directory
Dependency ranges changed: binary, cereal, directory, hmatrix, lens, temporary
Files
- creatur.cabal +26/−12
- src/ALife/Creatur/Genetics/BRGCWord8.hs +29/−5
- src/ALife/Creatur/Task.hs +2/−2
- test/ALife/Creatur/Genetics/BRGCWord8QC.hs +11/−1
- test/Main.hs +0/−46
- test/TestAll.hs +46/−0
creatur.cabal view
@@ -1,5 +1,5 @@ Name: creatur-Version: 5.2.1+Version: 5.2.3 Stability: experimental Synopsis: Framework for artificial life experiments. Description: A software framework for automating experiments@@ -23,6 +23,7 @@ License-file: LICENSE Copyright: (c) Amy de Buitléir 2010-2012 Homepage: https://github.com/mhwombat/creatur+Bug-reports: https://github.com/mhwombat/creatur/issues Author: Amy de Buitléir Maintainer: amy@nualeargais.ie Build-Type: Simple@@ -35,7 +36,7 @@ source-repository this type: git location: https://github.com/mhwombat/creatur.git- tag: 5.2.1+ tag: 5.2.3 library GHC-Options: -Wall -fno-warn-orphans@@ -66,13 +67,13 @@ base ==4.*, bytestring ==0.10.*, cond ==0.4.*,- cereal ==0.3.* || ==0.4.*,- directory ==1.2.*,+ cereal ==0.4.*,+ directory ==1.1 || ==1.2.*, filepath ==1.3.*, gray-extended ==1.*, hdaemonize ==0.4.*,- hmatrix ==0.14.* || ==0.15.*,- lens ==3.8.* || ==3.10.*,+ hmatrix ==0.14 || ==0.15.*,+ lens ==4.0.*, MonadRandom ==0.1.*, mtl ==2.1.*, old-locale ==1.0.*,@@ -86,22 +87,22 @@ Test-suite creatur-tests Type: exitcode-stdio-1.0- Main-is: Main.hs+ Main-is: TestAll.hs GHC-Options: -Wall Hs-source-dirs: test Build-Depends: array ==0.4.* || ==0.5.*, base ==4.*,- binary ==0.5.* || ==0.7.*,- cereal ==0.3.* || ==0.4.*,+ binary ==0.5.* || ==0.6.* || ==0.7.*,+ cereal ==0.4.*, creatur,- directory ==1.2.*,+ directory ==1.1 || ==1.2.*, filepath ==1.3.*,- hmatrix ==0.14.* || ==0.15.*,+ hmatrix ==0.14 || ==0.15.*, HUnit ==1.2.*, MonadRandom ==0.1.*, mtl ==2.1.*,- temporary ==1.1.*,+ temporary ==1.2.*, test-framework ==0.8.*, test-framework-hunit ==0.3.*, test-framework-quickcheck2 ==0.3.*,@@ -115,3 +116,16 @@ ALife.Creatur.Genetics.BRGCWord8QC ALife.Creatur.Genetics.BRGCWord16QC ALife.Creatur.Genetics.RecombinationQC++-- Benchmark creatur-bench+-- Type: exitcode-stdio-1.0+-- Main-is: BenchAll.hs+-- GHC-Options: -Wall+-- Hs-source-dirs: test+-- Build-Depends: +-- base ==4.*,+-- creatur,+-- criterion ==0.8.*,+-- test-framework ==0.8.*+-- Other-modules: ALife.Creatur.Genetics.BRGCWord8Bench+
src/ALife/Creatur/Genetics/BRGCWord8.hs view
@@ -55,6 +55,7 @@ import Control.Monad.State.Lazy (StateT, runState, execState, evalState) import qualified Control.Monad.State.Lazy as S (put, get, gets) import Data.Char (ord, chr)+import Data.Either (partitionEithers) import Data.Functor.Identity (Identity) import Data.Word (Word8, Word16) import GHC.Generics@@ -64,10 +65,10 @@ type Writer = StateT Sequence Identity write :: Genetic x => x -> Sequence-write x = execState (put x) []+write x = runWriter (put x) runWriter :: Writer () -> Sequence-runWriter w = execState w []+runWriter w = execState (w >> finalise) [] type Reader = StateT (Sequence, Int) Identity @@ -185,7 +186,17 @@ let low = fmap fromIntegral l :: Either [String] Word16 return . fmap grayToIntegral $ (+) <$> high <*> low -instance (Genetic a) => Genetic [a]+instance (Genetic a) => Genetic [a] where+ put xs = put n' >> mapM_ put xs+ where n = length xs+ n' = if n <= fromIntegral (maxBound :: Word16)+ then fromIntegral n+ else error "List too long" :: Word16+ get = do+ n <- get :: Reader (Either [String] Word16)+ case n of+ Right n' -> getList (fromIntegral n')+ Left s -> return $ Left s instance (Genetic a) => Genetic (Maybe a) @@ -198,11 +209,24 @@ -- Utilities -- +finalise :: Writer ()+finalise = do+ xs <- S.get+ S.put (reverse xs)++getList :: Genetic a => Int -> Reader (Either [String] [a])+getList n = do+ cs <- sequence $ replicate n get+ let (mss, xs) = partitionEithers cs+ if null mss+ then return $ Right xs+ else return $ Left (head mss)+ -- | Write a Word8 value to the genome without encoding it putRawWord8 :: Word8 -> Writer () putRawWord8 x = do xs <- S.get- S.put (xs ++ [x])+ S.put (x:xs) -- | Read a Word8 value from the genome without decoding it getRawWord8 :: Reader (Either [String] Word8)@@ -220,7 +244,7 @@ putRawWord8s :: [Word8] -> Writer () putRawWord8s ys = do xs <- S.get- S.put (xs ++ ys)+ S.put (reverse ys ++ xs) -- | Read a raw sequence of Word8 values from the genome getRawWord8s :: Int -> Reader (Either [String] [Word8])
src/ALife/Creatur/Task.hs view
@@ -70,7 +70,7 @@ atEndOfRound summaryProgram (a:_) <- lineup markDone a- -- do this first in case the next line triggers an exception+ -- ^^^ do first in case the next line triggers an exception withAgent agentProgram a -- The input parameter is a list of agents. The first agent in the@@ -89,7 +89,7 @@ atEndOfRound summaryProgram as <- lineup when (not $ null as) $ markDone (head as)- -- do this first in case the next line triggers an exception+ -- ^^^ do first in case the next line triggers an exception withAgents agentsProgram as atEndOfRound
test/ALife/Creatur/Genetics/BRGCWord8QC.hs view
@@ -19,6 +19,7 @@ import Prelude hiding (read) import ALife.Creatur.Genetics.BRGCWord8 import ALife.Creatur.Genetics.Analysis (Analysable)+import ALife.Creatur.Util (fromEither) import Control.Applicative ((<$>), (<*>)) import Data.Word (Word8, Word16) import GHC.Generics (Generic)@@ -32,6 +33,13 @@ where x = write g g' = read x +prop_rawWord8s_round_trippable :: [Word8] -> Property+prop_rawWord8s_round_trippable g = property $ g' == g+ where x = runWriter (putRawWord8s g)+ g' = fromEither (error "read returned Nothing") .+ runReader (getRawWord8s n) $ x+ n = length g+ data TestStructure = A | B Bool | C Word8 | D Word16 Char | E [TestStructure] deriving (Show, Eq, Generic) @@ -67,7 +75,9 @@ testProperty "prop_round_trippable - Word16" (prop_round_trippable :: Word16 -> Property), testProperty "prop_round_trippable - TestStructure"- (prop_round_trippable :: TestStructure -> Property)+ (prop_round_trippable :: TestStructure -> Property),+ testProperty "prop_rawWord8s_round_trippable"+ prop_rawWord8s_round_trippable ]
− test/Main.hs
@@ -1,46 +0,0 @@---------------------------------------------------------------------------- |--- Module : Main--- Copyright : (c) Amy de Buitléir 2012-2013--- License : BSD-style--- Maintainer : amy@nualeargais.ie--- Stability : experimental--- Portability : portable------ Runs the QuickCheck tests.-----------------------------------------------------------------------------module Main where--import ALife.Creatur.CounterQC (test)-import ALife.Creatur.ChecklistQC (test)-import ALife.Creatur.UniverseQC (test)-import ALife.Creatur.Database.FileSystemQC (test)-import ALife.Creatur.UtilQC (test)-import ALife.Creatur.Genetics.CodeQC (test)-import ALife.Creatur.Genetics.DiploidQC (test)-import ALife.Creatur.Genetics.RecombinationQC (test)-import ALife.Creatur.Genetics.BRGCBoolQC (test)-import ALife.Creatur.Genetics.BRGCWord8QC (test)-import ALife.Creatur.Genetics.BRGCWord16QC (test)--import Test.Framework as TF (defaultMain, Test)--tests :: [TF.Test]-tests = - [ - ALife.Creatur.CounterQC.test,- ALife.Creatur.ChecklistQC.test,- ALife.Creatur.UniverseQC.test,- ALife.Creatur.Database.FileSystemQC.test,- ALife.Creatur.UtilQC.test,- ALife.Creatur.Genetics.CodeQC.test,- ALife.Creatur.Genetics.DiploidQC.test,- ALife.Creatur.Genetics.RecombinationQC.test,- ALife.Creatur.Genetics.BRGCBoolQC.test,- ALife.Creatur.Genetics.BRGCWord8QC.test,- ALife.Creatur.Genetics.BRGCWord16QC.test- ]--main :: IO ()-main = defaultMain tests
+ test/TestAll.hs view
@@ -0,0 +1,46 @@+------------------------------------------------------------------------+-- |+-- Module : Main+-- Copyright : (c) Amy de Buitléir 2012-2013+-- License : BSD-style+-- Maintainer : amy@nualeargais.ie+-- Stability : experimental+-- Portability : portable+--+-- Runs the QuickCheck tests.+--+------------------------------------------------------------------------+module Main where++import ALife.Creatur.CounterQC (test)+import ALife.Creatur.ChecklistQC (test)+import ALife.Creatur.UniverseQC (test)+import ALife.Creatur.Database.FileSystemQC (test)+import ALife.Creatur.UtilQC (test)+import ALife.Creatur.Genetics.CodeQC (test)+import ALife.Creatur.Genetics.DiploidQC (test)+import ALife.Creatur.Genetics.RecombinationQC (test)+import ALife.Creatur.Genetics.BRGCBoolQC (test)+import ALife.Creatur.Genetics.BRGCWord8QC (test)+import ALife.Creatur.Genetics.BRGCWord16QC (test)++import Test.Framework as TF (defaultMain, Test)++tests :: [TF.Test]+tests = + [ + ALife.Creatur.CounterQC.test,+ ALife.Creatur.ChecklistQC.test,+ ALife.Creatur.UniverseQC.test,+ ALife.Creatur.Database.FileSystemQC.test,+ ALife.Creatur.UtilQC.test,+ ALife.Creatur.Genetics.CodeQC.test,+ ALife.Creatur.Genetics.DiploidQC.test,+ ALife.Creatur.Genetics.RecombinationQC.test,+ ALife.Creatur.Genetics.BRGCBoolQC.test,+ ALife.Creatur.Genetics.BRGCWord8QC.test,+ ALife.Creatur.Genetics.BRGCWord16QC.test+ ]++main :: IO ()+main = defaultMain tests