I need generate unique non-null
strings to be used as Dictionary
keys. I tried something like:
public static Gen<NonNull<string>> UniqueStrings()
{
return from s in Arb.Default.NonNull<string>().Generator
select s;
}
Then I use UniqueString()
in:
public static Arb<Foo> Foos()
{
// Foo's constructor will use the string parameter
// as key to an internal Dictionary
return (from nonNullString in UniqueStrings()
select new Foo(nonNullString.Item)).ToArbitrary();
}
However, I get an exception in properties testing Foo
because FsCheck sometimes generates the same string twice, resulting in a DuplicateKeyException
.
How can I generate unique strings to be passed into the constructor of Foo
?
Guid.NewGuid().ToString();
will be unique string. – Anglesite