Open rtfeldman opened 9 years ago
Oops sorry. Actually I have no idea what I was trying to do there. The comments say that the floats generated are between -50 and 50 and yet I somehow added the ability to generate any float.
Sorry about that, I guess this is one of those cases when I look at old code and go "what the hell was I thinking?".
Richard, which would you prefer, that the generator only generate small values, generate any values, or mostly small values but occasionally large ones?
In general I prefer to have investigators that explicitly incorporate likely-to-break values...in fact, come to think of it, I'd like to include 0 in the mix here too. :wink:
How about something like this:
float : Investigator Float
float =
let generator =
Random.frequency
[ (1, Random.constant 0)
, (7, Random.float -50 50)
, (2, Random.float (toFloat Random.minInt) (toFloat Random.maxInt))
] (Random.float -50 50)
in
investigator generator Shrink.float
And, don't worry too much about zero. The shrinking strategy tries 0 first when it finds something wrong.
I like it!
I do think zero is good to include anyway, because shrinking only comes up of there's a failure in the first place; if a test passes for nonzero values but fails for zero (a notorious source of edge case failures), I want it to fail!
The reason I messed this up with
percentage
was because I copy/pasted fromfloat
without noticing the same error!This fixes
float
in the same way.