Day 11
This commit is contained in:
68
test/Day11Spec.hs
Normal file
68
test/Day11Spec.hs
Normal file
@@ -0,0 +1,68 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Day11Spec (spec) where
|
||||
|
||||
import Data.Foldable (toList)
|
||||
import qualified Data.Sequence as S
|
||||
import Data.Text (Text)
|
||||
import Day11
|
||||
import Day11.Parser
|
||||
import Test.Hspec
|
||||
import Text.Heredoc
|
||||
import Data.Int (Int64)
|
||||
|
||||
testInput :: Text
|
||||
testInput =
|
||||
[str|Monkey 0:
|
||||
| Starting items: 79, 98
|
||||
| Operation: new = old * 19
|
||||
| Test: divisible by 23
|
||||
| If true: throw to monkey 2
|
||||
| If false: throw to monkey 3
|
||||
|
|
||||
|Monkey 1:
|
||||
| Starting items: 54, 65, 75, 74
|
||||
| Operation: new = old + 6
|
||||
| Test: divisible by 19
|
||||
| If true: throw to monkey 2
|
||||
| If false: throw to monkey 0
|
||||
|
|
||||
|Monkey 2:
|
||||
| Starting items: 79, 60, 97
|
||||
| Operation: new = old * old
|
||||
| Test: divisible by 13
|
||||
| If true: throw to monkey 1
|
||||
| If false: throw to monkey 3
|
||||
|
|
||||
|Monkey 3:
|
||||
| Starting items: 74
|
||||
| Operation: new = old + 3
|
||||
| Test: divisible by 17
|
||||
| If true: throw to monkey 0
|
||||
| If false: throw to monkey 1
|
||||
|]
|
||||
|
||||
exampleMonkeys :: [Monkey]
|
||||
exampleMonkeys = parseMonkeys testInput
|
||||
|
||||
spec :: Spec
|
||||
spec =
|
||||
describe "Day11" $ do
|
||||
describe "Part1" $ do
|
||||
it "parses" $ do
|
||||
head exampleMonkeys `shouldBe` Monkey 0 (S.fromList [79, 98]) (Multiply (Fixed 19)) 23 2 3 0
|
||||
_items (exampleMonkeys !! 1) `shouldBe` S.fromList [54, 65, 75, 74]
|
||||
it "runs part 1 monkey machine for 20 rounds" $ do
|
||||
let monkeys = runMonkeyMachine divideBy3 20 exampleMonkeys
|
||||
map _inspectionCount monkeys
|
||||
`shouldBe` [101, 95, 7, 105]
|
||||
map _inspectionCount (mostActiveMonkeys monkeys) `shouldBe` [105, 101]
|
||||
map _nr (mostActiveMonkeys monkeys) `shouldBe` [3, 0]
|
||||
monkeyBusiness (mostActiveMonkeys monkeys) `shouldBe` 10605
|
||||
|
||||
it "runs part 2 monkey machine for 10000 rounds" $ do
|
||||
let monkeys = runMonkeyMachine (worryLimit exampleMonkeys) 10000 exampleMonkeys
|
||||
map _inspectionCount monkeys
|
||||
`shouldBe` [52166, 47830, 1938, 52013]
|
||||
monkeyBusiness (mostActiveMonkeys monkeys) `shouldBe` 2713310158
|
||||
Reference in New Issue
Block a user