Skip to content

Commit 73bf6ec

Browse files
committed
Change the way to run tests a bit
1 parent 1020b21 commit 73bf6ec

File tree

10 files changed

+85
-91
lines changed

10 files changed

+85
-91
lines changed

Advent.elm

+6-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ program { input, parse1, parse2, compute1, compute2, tests1, tests2 } =
5656
type alias Test input output =
5757
{ description : String
5858
, input : String
59-
, expectedParsedInput : input
59+
, expectedParsedInput : Maybe input
6060
, expectedOutput : output
6161
}
6262

@@ -70,7 +70,10 @@ runTest puzzleType parse compute { description, input, expectedParsedInput, expe
7070
output =
7171
compute parsedInput
7272
in
73-
if parsedInput /= expectedParsedInput then
73+
if
74+
(expectedParsedInput /= Nothing)
75+
&& (expectedParsedInput /= Just parsedInput)
76+
then
7477
Debug.todo <|
7578
"\nTest \""
7679
++ description
@@ -79,7 +82,7 @@ runTest puzzleType parse compute { description, input, expectedParsedInput, expe
7982
++ " failed on `parse`:\n input: "
8083
++ Debug.toString input
8184
++ "\n expected: "
82-
++ Debug.toString expectedParsedInput
85+
++ Debug.toString (unsafeMaybe expectedParsedInput)
8386
++ "\n actual: "
8487
++ Debug.toString parsedInput
8588
++ "\n"

Template.elm

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ tests1 : List (Test Input1 Output1)
6666
tests1 =
6767
[{- Test "example"
6868
"input"
69-
-1
69+
Nothing -- Just "parsed-input"
7070
-1
7171
-}
7272
]

Year2017/Day25.elm

+53-49
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import Dict exposing (Dict)
55
import List.Extra
66

77

8-
main : Program Never ( Output, Output ) Never
8+
main : Program () ( Output, Output ) Never
99
main =
1010
Advent.program
11-
{ input = input
11+
{ input = input_
1212
, parse1 = parse
1313
, parse2 = parse
1414
, compute1 = compute1
@@ -81,11 +81,13 @@ run : Tape -> Input -> Int
8181
run tape { state, stepsToChecksum, rules, position } =
8282
if stepsToChecksum == 0 then
8383
countOnes tape
84+
8485
else
8586
let
8687
_ =
87-
if stepsToChecksum % 100000 == 0 then
88-
Debug.log (toString stepsToChecksum) ( state, position )
88+
if modBy 100000 stepsToChecksum == 0 then
89+
Debug.log (Debug.toString stepsToChecksum) ( state, position )
90+
8991
else
9092
( state, position )
9193

@@ -107,7 +109,7 @@ run tape { state, stepsToChecksum, rules, position } =
107109
rule.if1
108110

109111
_ ->
110-
Debug.crash "value other than 0/1 ????"
112+
Debug.todo "value other than 0/1 ????"
111113

112114
newPosition =
113115
move decision.moveTo position
@@ -118,12 +120,12 @@ run tape { state, stepsToChecksum, rules, position } =
118120
newTape =
119121
tape |> Dict.insert position decision.valueToWrite
120122
in
121-
run newTape
122-
{ state = newState
123-
, stepsToChecksum = stepsToChecksum - 1
124-
, rules = rules
125-
, position = newPosition
126-
}
123+
run newTape
124+
{ state = newState
125+
, stepsToChecksum = stepsToChecksum - 1
126+
, rules = rules
127+
, position = newPosition
128+
}
127129

128130

129131
move : Direction -> Int -> Int
@@ -173,39 +175,41 @@ In state B:
173175
- Write the value 1.
174176
- Move one slot to the right.
175177
- Continue with state A."""
176-
{ state = "A"
177-
, stepsToChecksum = 6
178-
, position = 0
179-
, rules =
180-
[ ( "A"
181-
, { if0 =
182-
{ valueToWrite = 1
183-
, moveTo = Right
184-
, nextState = "B"
185-
}
186-
, if1 =
187-
{ valueToWrite = 0
188-
, moveTo = Left
189-
, nextState = "B"
190-
}
191-
}
192-
)
193-
, ( "B"
194-
, { if0 =
195-
{ valueToWrite = 1
196-
, moveTo = Left
197-
, nextState = "A"
178+
(Just
179+
{ state = "A"
180+
, stepsToChecksum = 6
181+
, position = 0
182+
, rules =
183+
[ ( "A"
184+
, { if0 =
185+
{ valueToWrite = 1
186+
, moveTo = Right
187+
, nextState = "B"
188+
}
189+
, if1 =
190+
{ valueToWrite = 0
191+
, moveTo = Left
192+
, nextState = "B"
193+
}
198194
}
199-
, if1 =
200-
{ valueToWrite = 1
201-
, moveTo = Right
202-
, nextState = "A"
195+
)
196+
, ( "B"
197+
, { if0 =
198+
{ valueToWrite = 1
199+
, moveTo = Left
200+
, nextState = "A"
201+
}
202+
, if1 =
203+
{ valueToWrite = 1
204+
, moveTo = Right
205+
, nextState = "A"
206+
}
203207
}
204-
}
205-
)
206-
]
207-
|> Dict.fromList
208-
}
208+
)
209+
]
210+
|> Dict.fromList
211+
}
212+
)
209213
3
210214
]
211215

@@ -226,7 +230,7 @@ parse input =
226230
}
227231

228232
_ ->
229-
Debug.crash "wrong input!"
233+
Debug.todo "wrong input!"
230234

231235

232236
parseState : String -> State
@@ -246,7 +250,7 @@ parseChecksum string =
246250
|> List.reverse
247251
|> List.drop 1
248252
|> List.head
249-
|> Maybe.map Advent.toInt
253+
|> Maybe.map Advent.unsafeToInt
250254
|> Advent.unsafeMaybe
251255

252256

@@ -283,7 +287,7 @@ parseRule ruleLines =
283287
)
284288

285289
_ ->
286-
Debug.crash "wrong input??"
290+
Debug.todo "wrong input??"
287291

288292

289293
parseMoveTo : String -> Direction
@@ -307,7 +311,7 @@ parseDirection string =
307311
Right
308312

309313
_ ->
310-
Debug.crash "wrong input!"
314+
Debug.todo "wrong input!"
311315

312316

313317
parseValueToWrite : String -> Int
@@ -317,12 +321,12 @@ parseValueToWrite string =
317321
|> String.words
318322
|> List.reverse
319323
|> List.head
320-
|> Maybe.map Advent.toInt
324+
|> Maybe.map Advent.unsafeToInt
321325
|> Advent.unsafeMaybe
322326

323327

324-
input : String
325-
input =
328+
input_ : String
329+
input_ =
326330
"""Begin in state A.
327331
Perform a diagnostic checksum after 12523873 steps.
328332

Year2018/Day01.elm

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ tests2 : List (Test Input2 Output2)
106106
tests2 =
107107
[ Test "example"
108108
"+1\n-1"
109-
[ 1, -1 ]
109+
Nothing
110110
0
111111
, Test "example 2"
112112
"+3\n+3\n+4\n-2\n-4"
113-
[ 3, 3, 4, -2, -4 ]
113+
Nothing
114114
10
115115
, Test "example 3"
116116
"-6\n+3\n+8\n+5\n-6"
117-
[ -6, 3, 8, 5, -6 ]
117+
Nothing
118118
5
119119
]
120120

Year2018/Day03.elm

+7-5
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,13 @@ tests1 =
256256
#2 @ 3,1: 4x4
257257
#3 @ 5,5: 2x2
258258
#4 @ 3,3: 1x1"""
259-
[ Claim 1 (Rect 1 3 4 4)
260-
, Claim 2 (Rect 3 1 4 4)
261-
, Claim 3 (Rect 5 5 2 2)
262-
, Claim 4 (Rect 3 3 1 1)
263-
]
259+
(Just
260+
[ Claim 1 (Rect 1 3 4 4)
261+
, Claim 2 (Rect 3 1 4 4)
262+
, Claim 3 (Rect 5 5 2 2)
263+
, Claim 4 (Rect 3 3 1 1)
264+
]
265+
)
264266
4
265267
]
266268

Year2018/Day05.elm

+6-6
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,23 @@ tests1 : List (Test Input1 Output1)
138138
tests1 =
139139
[ Test "aA cancels out"
140140
"aA"
141-
(String.toList "aA")
141+
Nothing
142142
0
143143
, Test "two cancelations"
144144
"abBA"
145-
(String.toList "abBA")
145+
Nothing
146146
0
147147
, Test "nothing"
148148
"abAB"
149-
(String.toList "abAB")
149+
Nothing
150150
4
151151
, Test "nothing 2"
152152
"aabAAB"
153-
(String.toList "aabAAB")
153+
Nothing
154154
6
155155
, Test "large example"
156156
"dabAcCaCBAcCcaDA"
157-
(String.toList "dabAcCaCBAcCcaDA")
157+
Nothing
158158
10
159159
]
160160

@@ -163,7 +163,7 @@ tests2 : List (Test Input2 Output2)
163163
tests2 =
164164
[ Test "example"
165165
"dabAcCaCBAcCcaDA"
166-
(String.toList "dabAcCaCBAcCcaDA")
166+
Nothing
167167
4
168168
]
169169

Year2018/Day06.elm

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ tests1 =
211211
3, 4
212212
5, 5
213213
8, 9"""
214-
[ ( 1, 1 ), ( 1, 6 ), ( 8, 3 ), ( 3, 4 ), ( 5, 5 ), ( 8, 9 ) ]
214+
Nothing
215215
17
216216
]
217217

Year2018/Day07.elm

+1-8
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,7 @@ Step A must be finished before step D can begin.
253253
Step B must be finished before step E can begin.
254254
Step D must be finished before step E can begin.
255255
Step F must be finished before step E can begin."""
256-
[ Dependency 'C' 'A'
257-
, Dependency 'C' 'F'
258-
, Dependency 'A' 'B'
259-
, Dependency 'A' 'D'
260-
, Dependency 'B' 'E'
261-
, Dependency 'D' 'E'
262-
, Dependency 'F' 'E'
263-
]
256+
Nothing
264257
"CABDFE"
265258
]
266259

Year2018/Day08.elm

+1-9
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,7 @@ tests1 : List (Test Input1 Output1)
153153
tests1 =
154154
[ Test "example"
155155
"2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2"
156-
(Node
157-
[ Node [] [ 10, 11, 12 ]
158-
, Node
159-
[ Node [] [ 99 ]
160-
]
161-
[ 2 ]
162-
]
163-
[ 1, 1, 2 ]
164-
)
156+
Nothing
165157
138
166158
]
167159

Year2018/Day09.elm

+6-6
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ compute2 input =
201201

202202
tests1 : List (Test Input1 Output1)
203203
tests1 =
204-
[ Test "example 6" "30 players; last marble is worth 5807 points" (Input1 30 5807) 37305
205-
, Test "example 5" "21 players; last marble is worth 6111 points" (Input1 21 6111) 54718
206-
, Test "example 4" "17 players; last marble is worth 1104 points" (Input1 17 1104) 2764
207-
, Test "example 3" "13 players; last marble is worth 7999 points" (Input1 13 7999) 146373
208-
, Test "example 2" "10 players; last marble is worth 1618 points" (Input1 10 1618) 8317
209-
, Test "example" "9 players; last marble is worth 25 points" (Input1 9 25) 32
204+
[ Test "example 6" "30 players; last marble is worth 5807 points" Nothing 37305
205+
, Test "example 5" "21 players; last marble is worth 6111 points" Nothing 54718
206+
, Test "example 4" "17 players; last marble is worth 1104 points" Nothing 2764
207+
, Test "example 3" "13 players; last marble is worth 7999 points" Nothing 146373
208+
, Test "example 2" "10 players; last marble is worth 1618 points" Nothing 8317
209+
, Test "example" "9 players; last marble is worth 25 points" Nothing 32
210210
]
211211

212212

0 commit comments

Comments
 (0)