-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.fs
243 lines (213 loc) · 5.25 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
module Tests
open System
open System.Collections.Generic
open Xunit
[<Fact>]
let ``Day01 - Part1 - 1 Elf has 6000 calories`` () =
let input = "1000
2000
3000"
let result = Day1.FindMostCalories input Environment.NewLine Day1.Top1
Assert.Equal(6000, result)
[<Fact>]
let ``Day01 - Part1 - Elf with most calories has 24000 calories`` () =
let input = "1000
2000
3000
4000
5000
6000
7000
8000
9000
10000"
let result = Day1.FindMostCalories input Environment.NewLine Day1.Top1
Assert.Equal(24000, result)
[<Fact>]
let ``Day01 - Part2 - Top 3 elves have 45000 calories`` () =
let input = "1000
2000
3000
4000
5000
6000
7000
8000
9000
10000"
let result = Day1.FindMostCalories input Environment.NewLine Day1.Top3
Assert.Equal(45000, result)
[<Fact>]
let ``Day02 RockPaperScissors score part 1 is 15`` () =
let input = "A Y
B X
C Z
"
let result = Day2.RockPaperScissors input Environment.NewLine Day2.ScorePart1
Assert.Equal(15, result)
[<Fact>]
let ``Day02 RockPaperScissors score part 1 is 30`` () =
let input = "A Y
B X
C Z
A Y
B X
C Z
"
let result = Day2.RockPaperScissors input Environment.NewLine Day2.ScorePart1
Assert.Equal(30, result)
[<Fact>]
let ``Day02 RockPaperScissors score part 2 is 12`` () =
let input = "A Y
B X
C Z
"
let result = Day2.RockPaperScissors input Environment.NewLine Day2.ScorePart2
Assert.Equal(12, result)
[<Fact>]
let ``Day03 Rucksack priority sum is 157`` ()=
let input = "
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
"
let result = Day3.RucksackPriority input Environment.NewLine Day3.Part1
Assert.Equal(157, result)
[<Fact>]
let ``Day03 Rucksack priority sum is 70 when split into chunks``() =
let input = "
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
"
let result = Day3.RucksackPriority input Environment.NewLine Day3.Part2
Assert.Equal(70, result)
[<Fact>]
let ``Day04 Work assignments, there are 2 overlapping pairs``() =
let input = "
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8
"
let result = Day4.WorkAssignments input Environment.NewLine Day4.OverlappingPairs
Assert.Equal(2, result)
[<Fact>]
let ``Day04 Work assignments, there are 2 overlapping pairs with double digits``() =
let input = "
12-14,16-18
12-13,14-15
25-27,27-29
32-38,33-37
36-36,32-36
42-46,44-48
"
let result = Day4.WorkAssignments input Environment.NewLine Day4.OverlappingPairs
Assert.Equal(2, result)
[<Fact>]
let ``Day04 Work assignments, no overlapping pairs with double digits``() =
let input = "
6-92,4-5
4-5,6-92
"
let result = Day4.WorkAssignments input Environment.NewLine Day4.OverlappingPairs
Assert.Equal(0, result)
[<Fact>]
let ``Day04 Work assignments, 0 pairs with any overlap``() =
let input = "
2-4,6-8
2-3,4-5
"
let result = Day4.WorkAssignments input Environment.NewLine Day4.ConsecutiveOrOverlapping
Assert.Equal(0, result)
[<Fact>]
let ``Day04 Work assignments, 0 pairs with any overlap (reversed)``() =
let input = "
6-8,2-4
4-5,2-3
"
let result = Day4.WorkAssignments input Environment.NewLine Day4.ConsecutiveOrOverlapping
Assert.Equal(0, result)
[<Fact>]
let ``Day04 Work assignments, 8 pairs with any overlap``() =
let input = "
5-7,7-9
7-9,5-7
2-8,3-7
3-7,2-8
6-6,4-6
4-6,6-6
2-6,4-8
4-8,2-6
"
let result = Day4.WorkAssignments input Environment.NewLine Day4.ConsecutiveOrOverlapping
Assert.Equal(8, result)
[<Fact>]
let ``Day05 Crate stacking, result should be CMZ``() =
let input = " [D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
"
let stackSetup =
[
Day5.CrateStack<string>(["Z";"N"]);
Day5.CrateStack<string>(["M";"C";"D"]);
Day5.CrateStack<string>(["P"]);
]
let result = Day5.CrateStacking input Environment.NewLine 4 stackSetup false
Assert.Equal("CMZ", result)
[<Fact>]
let ``Day05 Crate stacking, result should be MCD for CrateStacker9001``() =
let input = " [D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
"
let stackSetup =
[
Day5.CrateStack<string>(["Z";"N"]);
Day5.CrateStack<string>(["M";"C";"D"]);
Day5.CrateStack<string>(["P"]);
]
let result = Day5.CrateStacking input Environment.NewLine 4 stackSetup true
Assert.Equal("MCD", result)
[<Fact>]
let ``Day05 Crate stacking, result should be DMP for CrateStacker9001``() =
let input = "
[D]
[N] [C]
[Z] [M] [P]
1 2 3
move 2 from 2 to 1
"
let stackSetup =
[
Day5.CrateStack<string>(["Z";"N"]);
Day5.CrateStack<string>(["M";"C";"D"]);
Day5.CrateStack<string>(["P"]);
]
let result = Day5.CrateStacking input Environment.NewLine 5 stackSetup true
Assert.Equal("DMP", result)
[<Theory>]
[<InlineData("bvwbjplbgvbhsrlpgdmjqwftvncz", 5)>]
[<InlineData("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw", 11)>]
let ``Day06 PacketMarker``(input, expected) =
let result = Day6.StartOfPacketMarker input Environment.NewLine
Assert.Equal(expected, result)