-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay1Spec.hs
78 lines (64 loc) · 1.78 KB
/
Day1Spec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{-# LANGUAGE QuasiQuotes #-}
module Day1Spec where
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Day1
( Digit(One, Three, Eight, Two),
logic,
parser2,
part1,
part2,
Answer(Answer) )
import Parser (parseAll)
import NeatInterpolation ( trimming )
import Test.Hspec ( describe, it, shouldBe, Spec )
parsePart2 :: T.Text -> Maybe [Digit]
parsePart2 = parseAll parser2 . T.unpack
spec :: Spec
spec = describe "Day 1" $ do
it "logic"
$ part1
[trimming|1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet|]
`shouldBe` [12, 38, 15, 77]
it "parsePart2 example 1"
$ parsePart2 "123"
`shouldBe` Just [One, Two, Three]
it "parsePart2 example 2"
$ parsePart2 "1a2b3"
`shouldBe` Just [One, Two, Three]
it "parsePart2 example 3"
$ parsePart2 "one2twone"
`shouldBe` Just [One, Two, Two, One]
it "parsePart2 example 4"
$ parsePart2 "aoneb2ttwone"
`shouldBe` Just [One, Two, Two, One]
it "parsePart2 example 5"
$ parsePart2 "aoneon2eighthree"
`shouldBe` Just [One, Two, Eight, Three]
it "parsePart2 example 6"
$ parsePart2 "eightwothree"
`shouldBe` Just [Eight, Two, Three]
it "parsePart2 example 6"
$ parsePart2 "threeeightwo"
`shouldBe` Just [Three, Eight, Two]
it "parsePart2 example 7"
$ parsePart2 "oneighthreeighthreeightwone"
`shouldBe` Just [One, Eight, Three, Eight, Three, Eight, Two, One]
it "part2"
$ part2
[trimming|
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
|]
`shouldBe` [29, 83, 13, 24, 42, 14, 76]
it "solve the puzzle" $ do
input <- T.readFile "resources/input1"
logic input `shouldBe` Answer 55712 55413