You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {-# LANGUAGE QuasiQuotes #-}
  2. module Day3Spec (spec) where
  3. import Test.Hspec
  4. import Text.Heredoc
  5. import Day3.Part1
  6. import Day3.Part2
  7. inputPart1 :: String
  8. inputPart1 = [str|vJrwpWtwJgWrhcsFMMfFFhFp
  9. |jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
  10. |PmmdzqPrVvPwwTWBwg
  11. |wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
  12. |ttgJtRGJQctTZtZT
  13. |CrZsJsPPZsGzwwsLwLmpwMDw
  14. |]
  15. inputPart2 :: String
  16. inputPart2 = [str|vJrwpWtwJgWrhcsFMMfFFhFp
  17. |jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
  18. |PmmdzqPrVvPwwTWBwg
  19. |wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
  20. |ttgJtRGJQctTZtZT
  21. |CrZsJsPPZsGzwwsLwLmpwMDw
  22. |]
  23. spec :: Spec
  24. spec =
  25. describe "Day2" $ do
  26. describe "Part1" $ do
  27. it "can determine Rucksack compartment contents" $ do
  28. splitContents simpleContents `shouldBe` ("abc", "dec")
  29. it "can find items that are in both compartments" $ do
  30. itemsInBoth simpleContents `shouldBe` "c"
  31. it "determines item priority" $ do
  32. itemPriority 'a' `shouldBe` Just 1
  33. it "determines priority of contents" $ do
  34. priority "abc" `shouldBe` 1 + 2 + 3
  35. it "determines rearangement priority" $ do
  36. rearrangementPriority inputPart1 `shouldBe` 157
  37. describe "Part2" $ do
  38. it "can split into groups" $ do
  39. length groups `shouldBe` 2
  40. it "can determine the badge of each group" $ do
  41. map badgeOfGroup groups `shouldBe` "rZ"
  42. it "determine the sum of badge priorities" $ do
  43. sumOfBadgePriorities inputPart2 `shouldBe` 70
  44. where
  45. simpleContents = "abcdec"
  46. groups = splitIntoGroups inputPart2