fantasyland/fantasy-check

"Method `shrink` not implemented for this input"

rpominov opened this issue · 6 comments

Is it ok to get this message "Method shrink not implemented for this input"? I mean is it a known limitation of this library, or a signal than something wrong with my setup?

This means that we don't have a way to shrink the type so that we understand where the input fails. Let's say we have a number that should pass the test if it's under 25, but fails when it's over 25. So shrink attempts to reduce the number to try and find where it fails, with the idea to help you understand where and when it fails.

The library has implemented some shrink methods already, but it's very limited atm: https://github.com/fantasyland/fantasy-check/blob/master/src%2Fshrink.js#L41.

Consider Tuple2, the library doesn't have any knowledge of how to reconstruct this in order to shrink. What could happen is that we could have a default shrink method which could just return an empty array so that it knows there is nothing to work on? But then it's missing the point of using this library by finding out where things break.

Hm, I think I understand. But is it ok to get this message randomly then? As I understand inputs are generated randomly, so sometimes we can fail on an input that we can shrink, and sometimes not.

So if you get the message randomly, that means the test fails for the given input. You should definitely implement the shrink method for your input type because it sounds like you could have a bug in the test.

I don't actually have my own inputs, I just use built-in tests that fantasy-check provides: https://github.com/rpominov/basic-streams/blob/70714f109243ddf414db1ee6640ea33c86016412/test/fantasyCheck.js

If I make a change in function that transforms instances of my type (Stream) to comparable values — drainToArray, so it would always return different values for different instances, tests fail.

And when they fail, sometimes I get something like Failed after 1 tries: -16008411611135, or Failed after 1 tries: (no value printed). And sometimes it Method shrink not implemented for this input

So the reason this happens is because we use AnyVal. AnyVal can be numerous things (String, Number, Boolean - https://github.com/fantasyland/fantasy-check/blob/master/src/arb.js#L83).

(no value printed)

This will be an empty string.

Method shrink not implemented for this input

This will be a boolean, as that isn't currently specified in the shrink methods.

Hope that makes more sense.

Cool, that means it's all good on my side. Thank you for the help.