day2: Write a basic unit test for part 1
This commit is contained in:
parent
418c7f13fb
commit
a497af5d30
|
@ -1,11 +1,12 @@
|
||||||
|
import Control.Exception (assert)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
instructions <- getContents
|
instructions <- getContents
|
||||||
let
|
putStrLn (solution1 instructions)
|
||||||
parsed = parseInstructions instructions
|
|
||||||
location = navigate parsed
|
solution1 :: String -> String
|
||||||
solution1 = uncurry (*) location
|
solution1 input = show (uncurry (*) (navigate (parseInstructions input)))
|
||||||
print solution1
|
|
||||||
|
|
||||||
parseInstructions :: String -> [(Int, Int)]
|
parseInstructions :: String -> [(Int, Int)]
|
||||||
parseInstructions instructions =
|
parseInstructions instructions =
|
||||||
|
@ -23,3 +24,18 @@ navigate instructions =
|
||||||
where
|
where
|
||||||
sumTuples :: (Int, Int) -> (Int, Int) -> (Int, Int)
|
sumTuples :: (Int, Int) -> (Int, Int) -> (Int, Int)
|
||||||
sumTuples (a, b) (c, d) = (a + c, b + d)
|
sumTuples (a, b) (c, d) = (a + c, b + d)
|
||||||
|
|
||||||
|
-- Tests
|
||||||
|
|
||||||
|
testInput1 :: String
|
||||||
|
testInput1 = unlines [
|
||||||
|
"forward 5",
|
||||||
|
"down 5",
|
||||||
|
"forward 8",
|
||||||
|
"up 3",
|
||||||
|
"down 8",
|
||||||
|
"forward 2"
|
||||||
|
]
|
||||||
|
|
||||||
|
test1 :: String
|
||||||
|
test1 = assert ((solution1 testInput1) == "150") "success"
|
||||||
|
|
Loading…
Reference in a new issue