For FsCheck 1.x, I found a solution that includes modifying the default random string generator:
public class MyArbitraries { public static Arbitrary<string> String() { var nulls = Any.Value<string>(null); var nonnulls = Arb.Default.String().Generator; return Any.GeneratorIn(nulls, nonnulls).ToArbitrary; } }
and then initialize it with
DefaultArbitraries.Add<MyArbitraries>();
Then the test in question does not fit, as intended:
Spec.ForAny<string>(s => s != null).QuickCheck()
This will create about 50% zeros and 50% random strings, the scales can be adjusted:
Spec.ForAny<string>(s => true) .Classify(s => s==null, "null") .Classify(s => s!=null, "not null") .QuickCheck();
However, effectively overlapping the default line generator may not be practical if the decision to include a default value of zero was intentional and not an error in the library. And, if it were a mistake, it would distort the distribution when fixed.
Alapago
source share