adventofcode/test/Spec.hs

133 lines
4.5 KiB
Haskell
Raw Normal View History

2017-12-09 02:21:39 +00:00
{-# LANGUAGE OverloadedStrings #-}
2017-12-01 09:41:18 +00:00
import Test.Tasty
import Test.Tasty.HUnit
2017-12-09 10:09:32 +00:00
import Control.Monad (when)
2017-12-01 09:41:18 +00:00
2017-12-11 14:59:07 +00:00
import qualified Day01
import qualified Day02
import qualified Day05
import qualified Day06
import qualified Day07
import qualified Day08
2017-12-10 12:07:53 +00:00
import qualified Day10
2017-12-11 15:36:18 +00:00
import qualified Day11
2017-12-12 10:04:43 +00:00
import qualified Day12
import qualified Day13
2017-12-01 09:41:18 +00:00
main :: IO ()
main = defaultMain $
2017-12-02 07:55:51 +00:00
testGroup "Advent Of Code 2017"
[
2017-12-01 09:41:18 +00:00
testGroup "Day 1"
[ testGroup "solution 1"
2017-12-11 14:59:07 +00:00
[ testCase "1122 is 3" $ Day01.solution1 "1122" @?= 3
, testCase "1111 is 4" $ Day01.solution1 "1111" @?= 4
, testCase "1234 is 0" $ Day01.solution1 "1234" @?= 0
, testCase "91212129 is 9" $ Day01.solution1 "91212129" @?= 9
2017-12-01 09:41:18 +00:00
]
, testGroup "solution 2"
2017-12-11 14:59:07 +00:00
[ testCase "1212 is 6" $ Day01.solution2 "1212" @?= 6
, testCase "1221 is 0" $ Day01.solution2 "1221" @?= 0
, testCase "123425 is 0" $ Day01.solution2 "123425" @?= 4
, testCase "123123 is 12" $ Day01.solution2 "123123" @?= 12
, testCase "12131415 is 4" $ Day01.solution2 "12131415" @?= 4
2017-12-01 09:41:18 +00:00
]
]
2017-12-02 07:55:51 +00:00
, testGroup "Day 2"
[ testCase "example problem 1" $
2017-12-11 14:59:07 +00:00
Day02.solution1 [[5,1,9,5],[7,5,3],[2,4,6,8]] @?= 18
2017-12-02 07:55:51 +00:00
, testCase "example problem 2" $
2017-12-11 14:59:07 +00:00
Day02.solution2 [[5,9,2,8],[9,4,7,3],[3,8,6,5]] @?= 9
2017-12-02 07:55:51 +00:00
]
2017-12-06 22:19:26 +00:00
, testGroup "Day 5"
[ testCaseSteps "example problem 1" $ \step -> do
step "Loading input"
2017-12-11 14:59:07 +00:00
input <- Day05.testArray
2017-12-06 22:19:26 +00:00
step "Running solution 1"
2017-12-11 14:59:07 +00:00
sol1 <- Day05.solution1 input
2017-12-06 22:19:26 +00:00
when (sol1 /= 5) (assertFailure "Should be 5 steps")
, testCaseSteps "example problem 2" $ \step -> do
step "Loading input"
2017-12-11 14:59:07 +00:00
input <- Day05.testArray
2017-12-06 22:19:26 +00:00
step "Running solution 2"
2017-12-11 14:59:07 +00:00
sol2 <- Day05.solution2 input
2017-12-06 22:19:26 +00:00
when (sol2 /= 10) (assertFailure "Day 6 solution 2 on the example should be 4")
]
, testGroup "Day 6"
[ testCaseSteps "example problem 1" $ \step -> do
step "Loading input"
2017-12-11 14:59:07 +00:00
input <- Day06.testArray
2017-12-06 22:19:26 +00:00
step "Running solution 1"
2017-12-11 14:59:07 +00:00
sol1 <- Day06.solution1 input
2017-12-06 22:19:26 +00:00
when (sol1 /= 5) (assertFailure "Should be 5 steps")
, testCaseSteps "example problem 2" $ \step -> do
step "Loading input"
2017-12-11 14:59:07 +00:00
input <- Day06.testArray
2017-12-06 22:19:26 +00:00
step "Running solution 2"
2017-12-11 14:59:07 +00:00
sol2 <- Day06.solution2 input
2017-12-06 22:19:26 +00:00
when (sol2 /= 4) (assertFailure "Day 6 solution 2 on the example should be 4")
]
2017-12-09 02:21:39 +00:00
, testGroup "Day 7"
[ testCaseSteps "example problem 1" $ \step -> do
step "Running solution 1"
2017-12-11 14:59:07 +00:00
let input = Day07.testNodes
let sol1 = maybe "" Day07.name (Day07.rootOf input)
2017-12-09 02:21:39 +00:00
when (sol1 /= "tknk") (assertFailure "The root should be tknk")
2017-12-09 02:27:34 +00:00
, testCase "example on solution 2" $
2017-12-11 14:59:07 +00:00
maybe 0 snd (Day07.solution2 Day07.testNodes) @?= 60
2017-12-09 02:21:39 +00:00
]
2017-12-09 10:09:32 +00:00
, testGroup "Day 8"
[ testCase "example problem 1" $
2017-12-11 14:59:07 +00:00
Day08.solution1 Day08.testInstructions @?= 1
2017-12-09 10:09:32 +00:00
, testCase "example problem 1" $
2017-12-11 14:59:07 +00:00
Day08.solution2 Day08.testInstructions @?= 10
2017-12-09 10:09:32 +00:00
]
2017-12-10 12:07:53 +00:00
, testGroup "Day 10"
[ testCase "example 1" $
Day10.solution1 Day10.testInput @?= 12
2017-12-10 13:41:52 +00:00
, testCase "solution 2 empty" $
Day10.solution2 "" @?= "a2582a3a0e66e6e86e3812dcb672a272"
, testCase "solution 2 AoC 2017" $
Day10.solution2 "AoC 2017" @?= "33efeb34ea91902bb2f59c9920caa6cd"
, testCase "solution 2 1,2,3" $
Day10.solution2 "1,2,3" @?= "3efbe78a8d82f29979031a4aa0b16a9d"
, testCase "solution 2 1,2,4" $
Day10.solution2 "1,2,4" @?= "63960835bcdc130f0b66d7ff4f6a5a8e"
2017-12-10 12:07:53 +00:00
]
2017-12-11 15:36:18 +00:00
, testGroup "Day 11"
[ testGroup "Solution 1"
[ testCase "Example 1" $
Day11.solution1 (Day11.parseTxt "ne,ne,ne") @?= 3
, testCase "Example 2" $
Day11.solution1 (Day11.parseTxt "ne,ne,sw,sw") @?= 0
, testCase "Example 3" $
Day11.solution1 (Day11.parseTxt "ne,ne,s,s") @?= 2
, testCase "Example 4" $
Day11.solution1 (Day11.parseTxt "se,sw,se,sw,sw") @?= 3
]
]
2017-12-12 10:04:43 +00:00
, testGroup "Day 12"
[ testGroup "Solution 1"
[ testCase "Example" $
fmap Day12.solution1 (Day12.parseTxt Day12.testTxt) @?= Just 6
]
, testGroup "Solution 2"
[ testCase "Example" $
fmap Day12.solution2 (Day12.parseTxt Day12.testTxt) @?= Just 2
]
]
, testGroup "Day 13"
[ testGroup "Solution 1"
[ testCase "Example" $
fmap Day13.solution1
(fmap Day13.mkAppState
(Day13.parseTxt Day13.testInput)) @?= Just 24
]
, testGroup "Solution 2"
[ testCase "Example" $
fmap Day13.solution2 (Day13.parseTxt Day13.testInput) @?= Just 10
]
]
]