I get some warnings on the following code containing code contracts.
public static int Min(IEnumerable<int> set)
{
Contract.Requires(set != null);
Contract.Requires(set.Any());
Contract.Ensures(Contract.ForAll(set, x => x >= Contract.Result<int>()));
int min = set.Min();
return min;
}
static void Main(string[] args)
{
Console.WriteLine(Min(new int[] {3,4,5}));
Console.WriteLine(Min(new int[] {})); // should fail
}
I get the following warnings:
Requires unproven: set.Any() on Min(new int[] {3,4,5})
Ensures unproven: Contract.ForAll(set, x => x > Contract.Result<int>())
Two questions:
My postcondition states x >= Contract.Result(), but the "ensures unproven" warning states x > Contract.Result(). (Greather or equal vs. Greather) How can this happen?
Why can't set.Any() proven in the above statement?
Thank you in advance.