Skip to content

Commit c5815fc

Browse files
committed
Make debugging RandomRuns easier to work with
1 parent c9fb1c3 commit c5815fc

1 file changed

Lines changed: 47 additions & 26 deletions

File tree

src/Simplify.elm

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ import Simplify.Cmd exposing (SimplifyCmd, SimplifyCmdType(..))
3232
import Test.Expectation exposing (Expectation(..))
3333

3434

35+
shouldLogFirstFailure : Bool
36+
shouldLogFirstFailure =
37+
False
38+
39+
40+
shouldLogShrinkingProgress : Bool
41+
shouldLogShrinkingProgress =
42+
False
43+
44+
45+
shouldLogShrinkedAttempts : Bool
46+
shouldLogShrinkedAttempts =
47+
False
48+
49+
3550
type alias State a =
3651
{ getExpectation : a -> Expectation
3752
, fuzzer : Fuzzer a
@@ -61,12 +76,14 @@ andThen fn { newState } =
6176

6277
simplify : State a -> ( a, RandomRun, Expectation )
6378
simplify state =
64-
{-
65-
let
66-
_ =
67-
Debug.log "--------------" ()
68-
in
69-
-}
79+
let
80+
_ =
81+
if shouldLogFirstFailure then
82+
logRun "Found failure with RandomRun" state.randomRun
83+
84+
else
85+
state.randomRun
86+
in
7087
if RandomRun.isEmpty state.randomRun then
7188
-- We can't do any better
7289
( state.value, state.randomRun, state.expectation )
@@ -77,12 +94,14 @@ simplify state =
7794

7895
simplifyWhileProgress : State a -> ( a, RandomRun, Expectation )
7996
simplifyWhileProgress state =
80-
{-
81-
let
82-
_ =
83-
logState "\ncurrent best" state
84-
in
85-
-}
97+
let
98+
_ =
99+
if shouldLogShrinkingProgress then
100+
logState "\ncurrent best" state
101+
102+
else
103+
state
104+
in
86105
let
87106
nextState =
88107
simplifyOnce state
@@ -160,10 +179,14 @@ logState label state =
160179
runCmd : SimplifyCmd -> State a -> SimplifyResult a
161180
runCmd cmd state =
162181
let
163-
{-
164-
_ =
165-
logRun ("trying " ++ Debug.toString cmd.type_ ++ " on") state.randomRun
166-
-}
182+
_ =
183+
if shouldLogShrinkedAttempts then
184+
logRun ("trying " ++ Debug.toString cmd.type_ ++ " on") state.randomRun
185+
186+
else
187+
state.randomRun
188+
in
189+
let
167190
result =
168191
case cmd.type_ of
169192
DeleteChunkAndMaybeDecrementPrevious chunk ->
@@ -190,16 +213,14 @@ runCmd cmd state =
190213
SwapChunkWithNeighbour chunk ->
191214
swapChunkWithNeighbour chunk state
192215
in
193-
{-
194-
let
195-
_ =
196-
if result.wasImprovement then
197-
logState "Success" result.newState
198-
199-
else
200-
result.newState
201-
in
202-
-}
216+
let
217+
_ =
218+
if result.wasImprovement && shouldLogShrinkingProgress then
219+
logState "Success" result.newState
220+
221+
else
222+
result.newState
223+
in
203224
result
204225

205226

0 commit comments

Comments
 (0)