-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.fs
206 lines (173 loc) · 6.45 KB
/
Tests.fs
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
module AoC2020.Tests
open Xunit
open Xunit.Abstractions
open AoC2020.Utils
open AoC2020.Day1
open AoC2020.Day2
open AoC2020.Day3
open AoC2020.Day4
open AoC2020.Day5
open AoC2020.Day6
open AoC2020.Day7
open AoC2020.Day8
open AoC2020.Day9
open AoC2020.Day10
open AoC2020.Day11
open AoC2020.Day12
open AoC2020.Day13
open AoC2020.Day14
open AoC2020.Day16
open AoC2020.Day18
open AoC2020.Day24
open AoC2020.Day25
type Puzzles(o: ITestOutputHelper) =
[<Fact>]
let ``day 1`` () =
Assert.Equal(858496L, day1 "1" ())
Assert.Equal(263819430L, day1part2 "1" ())
[<Fact>]
let ``day 2`` () =
Assert.Equal(524L, day2 "2" ())
Assert.Equal(485L, day2part2 "2" ())
[<Fact>]
let ``day 3`` () =
let result = toboccan "test3" 3 1
Assert.Equal(7L, result)
Assert.Equal(265L, day3 "3" ())
Assert.Equal(3154761400L, day3part2 "3" ())
[<Fact>]
let ``day 4`` () =
let result = countValidPassports "test4" validate
Assert.Equal(2L, result)
Assert.Equal(260L, day4 "4" ())
Assert.Equal(153L, day4part2 "4" ())
[<Fact>]
let ``day 4 valid`` () =
let result = countValidPassports "valid4" validate2
Assert.Equal(4L, result)
[<Fact>]
let ``day 4 invalid`` () =
let result = countValidPassports "invalid4" validate2
Assert.Equal(0L, result)
[<Fact>]
let ``day 4 fields`` () =
Assert.True(validateByr "2002")
Assert.False(validateByr "2003")
Assert.True(validateHgt "60in")
Assert.True(validateHgt "190cm")
Assert.False(validateHgt "190in")
Assert.False(validateHgt "190")
Assert.True(validateHcl "#123abc")
Assert.False(validateHcl "#123abz")
Assert.False(validateHcl "123abc")
Assert.True(validateEcl "brn")
Assert.False(validateEcl "wat")
Assert.True(validatePid "000000001")
Assert.False(validatePid "0123456789")
[<Fact>]
let ``day 5`` () =
// BFFFBBFRRR: row 70, column 7, seat ID 567.
Assert.Equal(567, makeNumber "BFFFBBFRRR")
Assert.Equal((70, 7), getRowAndCol 567)
// FFFBBBFRRR: row 14, column 7, seat ID 119.
Assert.Equal(119, makeNumber "FFFBBBFRRR")
Assert.Equal((14, 7), getRowAndCol 119)
// BBFFBBFRLL: row 102, column 4, seat ID 820.
Assert.Equal(820, makeNumber "BBFFBBFRLL")
Assert.Equal((102, 4), getRowAndCol 820)
Assert.Equal(850L, day5 "5" ())
Assert.Equal(599L, day5part2 "5" ())
[<Fact>]
let ``day 6`` () =
Assert.Equal(11L, readInputDelimByEmptyLine "test6" |> countAnswers)
Assert.Equal(6L, day6part2 "test6b" ())
Assert.Equal(6506L, day6 "6" ())
Assert.Equal(3243L, day6part2 "6" ())
()
[<Fact>]
let ``day 7`` () =
Assert.Equal(4L, day7 "test7" ())
Assert.Equal(289L, day7 "7" ())
Assert.Equal(32L, day7part2 "test7" ())
Assert.Equal(126L, day7part2 "test7b" ())
Assert.Equal(30055L, day7part2 "7" ())
[<Fact>]
let ``day 8`` () =
Assert.Equal(5L, day8 "test8" ())
Assert.Equal(1451L, day8 "8" ())
Assert.Equal(8L, day8part2 "test8" ())
Assert.Equal(1160L, day8part2 "8" ())
[<Fact>]
let ``day 9`` () =
Assert.Equal(127L, day9 "test9" 5 ())
Assert.Equal(393911906L, day9 "9" 25 ())
Assert.Equal(62L, day9part2 "test9" 5 ())
[<Fact>]
let day10 () =
Assert.Equal(35L, day10 "test10" ())
Assert.Equal(220L, day10 "test10b" ())
Assert.Equal(1885L, day10 "10" ())
[<Fact>]
let ``day10 part 2`` () =
Assert.Equal(8L, day10part2 "test10" ())
Assert.Equal(19208L, day10part2 "test10b" ())
Assert.Equal(2024782584832L, day10part2 "10" ())
[<Fact>]
let ``day 11`` () =
Assert.Equal(37L, day11 "test11" "1" ())
Assert.Equal(2152L, day11 "11" "1" ())
[<Fact>]
let ``day 11 part 2 visibility algorithm`` () =
Assert.Equal(8L, testVisibility "test11b1" 4 3 ())
Assert.Equal(0L, testVisibility "test11b2" 1 1 ())
Assert.Equal(0L, testVisibility "test11b3" 3 3 ())
[<Fact>]
let ``day 12`` () =
Assert.Equal(25L, day12 "test12" ())
Assert.Equal(759L, day12 "12" ())
[<Fact>]
let ``day 13`` () =
Assert.Equal(295L, day13 "test13" ())
Assert.Equal(4782L, day13 "13" ())
[<Fact>]
let ``day 13 part 2`` () =
Assert.Equal(1068781L, solvePart2 "7,13,x,x,59,x,31,19")
Assert.Equal(3417L, solvePart2 "17,x,13,19")
Assert.Equal(754018L, solvePart2 "67,7,59,61")
Assert.Equal(779210L, solvePart2 "67,x,7,59,61")
Assert.Equal(1261476L, solvePart2 "67,7,x,59,61")
Assert.Equal(1202161486L, solvePart2 "1789,37,47,1889")
[<Fact>]
let ``day 14`` () =
Assert.Equal(165L, day14 "test14" ())
Assert.Equal(12512013221615L, day14 "14" ())
Assert.Equal(3905642473893L, day14part2 "14" ())
[<Fact>]
let ``day 16`` () =
Assert.Equal(71L, day16 "test16" ())
Assert.Equal(19093L, day16 "16" ())
Assert.Equal(5311123569883L, day16part2 "16" ())
[<Fact>]
let ``day 18`` () =
Assert.Equal(51L, (calculate p1) "1 + (2 * 3) + (4 * (5 + 6))")
Assert.Equal(71L, (calculate p1) "1 + 2 * 3 + 4 * 5 + 6")
Assert.Equal(26L, (calculate p1) "2 * 3 + (4 * 5)")
Assert.Equal(437L, (calculate p1) "5 + (8 * 3 + 9 + 3 * 4 * 3)")
Assert.Equal(12240L, (calculate p1) "5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))")
Assert.Equal(13632L, (calculate p1) "((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2")
Assert.Equal(51L, (calculate p2) "1 + (2 * 3) + (4 * (5 + 6))")
Assert.Equal(231L, (calculate p2) "1 + 2 * 3 + 4 * 5 + 6")
Assert.Equal(46L, (calculate p2) "2 * 3 + (4 * 5)")
Assert.Equal(1445L, (calculate p2) "5 + (8 * 3 + 9 + 3 * 4 * 3)")
Assert.Equal(669060L, (calculate p2) "5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))")
Assert.Equal(23340L, (calculate p2) "((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2")
[<Fact>]
let day24 () =
Assert.Equal(10L, day24 "test24" ())
Assert.Equal(549L, day24 "24" ())
Assert.Equal(37L, day24part2 "test24" 10 ())
Assert.Equal(2208L, day24part2 "test24" 100 ())
[<Fact>]
let day25 () =
Assert.Equal(14897079L, day25 5764801I 17807724I ())
Assert.Equal(9620012L, day25 3418282I 8719412I ())