From a497af5d302e62aca6390c322bbc05d5db9d8884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Fri, 3 Dec 2021 21:33:12 +0000 Subject: [PATCH] day2: Write a basic unit test for part 1 --- 2/navigator.hs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/2/navigator.hs b/2/navigator.hs index 05da590..5349949 100644 --- a/2/navigator.hs +++ b/2/navigator.hs @@ -1,11 +1,12 @@ +import Control.Exception (assert) + main :: IO () main = do instructions <- getContents - let - parsed = parseInstructions instructions - location = navigate parsed - solution1 = uncurry (*) location - print solution1 + putStrLn (solution1 instructions) + +solution1 :: String -> String +solution1 input = show (uncurry (*) (navigate (parseInstructions input))) parseInstructions :: String -> [(Int, Int)] parseInstructions instructions = @@ -23,3 +24,18 @@ navigate instructions = where sumTuples :: (Int, Int) -> (Int, Int) -> (Int, Int) 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"