{-# LANGUAGE QuasiQuotes #-} module Day3Spec (spec) where import Test.Hspec import Text.Heredoc import Day3.Part1 import Day3.Part2 inputPart1 :: String inputPart1 = [str|vJrwpWtwJgWrhcsFMMfFFhFp |jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL |PmmdzqPrVvPwwTWBwg |wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn |ttgJtRGJQctTZtZT |CrZsJsPPZsGzwwsLwLmpwMDw |] inputPart2 :: String inputPart2 = [str|vJrwpWtwJgWrhcsFMMfFFhFp |jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL |PmmdzqPrVvPwwTWBwg |wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn |ttgJtRGJQctTZtZT |CrZsJsPPZsGzwwsLwLmpwMDw |] spec :: Spec spec = describe "Day3" $ do describe "Part1" $ do it "can determine Rucksack compartment contents" $ do splitContents simpleContents `shouldBe` ("abc", "dec") it "can find items that are in both compartments" $ do itemsInBoth simpleContents `shouldBe` "c" it "determines item priority" $ do itemPriority 'a' `shouldBe` Just 1 it "determines priority of contents" $ do priority "abc" `shouldBe` 1 + 2 + 3 it "determines rearangement priority" $ do rearrangementPriority inputPart1 `shouldBe` 157 describe "Part2" $ do it "can split into groups" $ do length groups `shouldBe` 2 it "can determine the badge of each group" $ do map badgeOfGroup groups `shouldBe` "rZ" it "determine the sum of badge priorities" $ do sumOfBadgePriorities inputPart2 `shouldBe` 70 where simpleContents = "abcdec" groups = splitIntoGroups inputPart2