Skip to content

Commit

Permalink
added error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mhwombat committed Jun 23, 2016
1 parent ce1d3d6 commit 12abdc5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion creatur-wains.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: creatur-wains
Version: 8.4.2
Version: 8.4.3
Stability: experimental
Description: An artificial agent called the "Wain", designed to
run in the Créatúr framework. Wains have sufficient
Expand Down
16 changes: 9 additions & 7 deletions src/ALife/Creatur/Wain/MuserInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ instance Show Muser where
show (Muser o d) = "makeMuser " ++ show o ++ " " ++ show d

instance Statistical Muser where
stats (Muser os d) = [iStat "depth" d,
dStat "default energy outcome" . pm1ToDouble $ os !! 0,
dStat "default passion outcome" . pm1ToDouble $ os !! 1,
dStat "default boredom outcome" . pm1ToDouble $ os !! 2,
dStat "default litterSize outcome" . pm1ToDouble $ os !! 3]
stats (Muser (eo:po:bo:lso:_) d) = [iStat "depth" d,
dStat "default energy outcome" . pm1ToDouble $ eo,
dStat "default passion outcome" . pm1ToDouble $ po,
dStat "default boredom outcome" . pm1ToDouble $ bo,
dStat "default litterSize outcome" . pm1ToDouble $ lso]
stats _ = error "default outcome list is too short"

-- | Constructor
makeMuser :: [PM1Double] -> Word8 -> Muser
makeMuser os d
| d == 0 = error "zero depth"
| otherwise = Muser os d
| d == 0 = error "zero depth"
| length os < 4 = error "default outcome list is too short"
| otherwise = Muser os d

-- | Given a set of scenarios paired with the probability that each
-- scenario is true, returns a list of responses to consider paired
Expand Down
2 changes: 1 addition & 1 deletion test/ALife/Creatur/Wain/MuserQC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Test.QuickCheck

sizedArbMuser :: Int -> Gen Muser
sizedArbMuser n = do
o <- arbitrary
o <- vectorOf 4 arbitrary
d <- choose (1, min 3 (fromIntegral n + 1))
return $ makeMuser o d

Expand Down

0 comments on commit 12abdc5

Please sign in to comment.