123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- {-# LANGUAGE QuasiQuotes #-}
-
- module Day10Spec (spec) where
-
- import Control.Arrow ((>>>))
- import Day10
- import Test.Hspec
- import Text.Heredoc
-
- testInput :: String
- testInput = [str|noop
- |addx 3
- |addx -5
- |]
-
- testProgram :: [Instruction]
- testProgram = [Noop, Addx 3, Addx (-5)]
-
- testInput2 :: String
- testInput2 = [str|addx 15
- |addx -11
- |addx 6
- |addx -3
- |addx 5
- |addx -1
- |addx -8
- |addx 13
- |addx 4
- |noop
- |addx -1
- |addx 5
- |addx -1
- |addx 5
- |addx -1
- |addx 5
- |addx -1
- |addx 5
- |addx -1
- |addx -35
- |addx 1
- |addx 24
- |addx -19
- |addx 1
- |addx 16
- |addx -11
- |noop
- |noop
- |addx 21
- |addx -15
- |noop
- |noop
- |addx -3
- |addx 9
- |addx 1
- |addx -3
- |addx 8
- |addx 1
- |addx 5
- |noop
- |noop
- |noop
- |noop
- |noop
- |addx -36
- |noop
- |addx 1
- |addx 7
- |noop
- |noop
- |noop
- |addx 2
- |addx 6
- |noop
- |noop
- |noop
- |noop
- |noop
- |addx 1
- |noop
- |noop
- |addx 7
- |addx 1
- |noop
- |addx -13
- |addx 13
- |addx 7
- |noop
- |addx 1
- |addx -33
- |noop
- |noop
- |noop
- |addx 2
- |noop
- |noop
- |noop
- |addx 8
- |noop
- |addx -1
- |addx 2
- |addx 1
- |noop
- |addx 17
- |addx -9
- |addx 1
- |addx 1
- |addx -3
- |addx 11
- |noop
- |noop
- |addx 1
- |noop
- |addx 1
- |noop
- |noop
- |addx -13
- |addx -19
- |addx 1
- |addx 3
- |addx 26
- |addx -30
- |addx 12
- |addx -1
- |addx 3
- |addx 1
- |noop
- |noop
- |noop
- |addx -9
- |addx 18
- |addx 1
- |addx 2
- |noop
- |noop
- |addx 9
- |noop
- |noop
- |noop
- |addx -1
- |addx 2
- |addx -37
- |addx 1
- |addx 3
- |noop
- |addx 15
- |addx -21
- |addx 22
- |addx -6
- |addx 1
- |noop
- |addx 2
- |addx 1
- |noop
- |addx -10
- |noop
- |noop
- |addx 20
- |addx 1
- |addx 2
- |addx 2
- |addx -6
- |addx -11
- |noop
- |noop
- |noop
- |]
-
- spec :: Spec
- spec =
- describe "Day10" $ do
- describe "Part1" $ do
- it "parses" $ do
- parseProgram testInput `shouldBe` testProgram
- it "executes" $ do
- executeProgram testProgram `shouldBe` [1,1,1,4,4,-1]
- it "executes larger program" $ do
- let registerValues = parseProgram >>> executeProgram $ testInput2
- registerValues !! 20 `shouldBe` 21
- registerValues !! 60 `shouldBe` 19
- registerValues !! 100 `shouldBe` 18
- registerValues !! 140 `shouldBe` 21
- registerValues !! 180 `shouldBe` 16
- registerValues !! 220 `shouldBe` 18
- it "computes signal strength" $ do
- let registerValues = parseProgram >>> executeProgram $ testInput2
- signalStrength registerValues `shouldBe` 13140
- it "prints a crt" $ do
- let registerValues = parseProgram >>> executeProgram $ testInput2
- putStrLn $ draw registerValues
- it "sprites drawn" $ do
- isSpriteDrawn 1 1 `shouldBe` True
- isSpriteDrawn 1 1 `shouldBe` True
|