I'm playing around with code contracts and got a simple method inserting a given count of space characters between each character.
e.g.
Hello -> H e l l o
World -> W o r l d
The method InsertSpaceBetweenLetters is implemented within a class that offers some string-property S, the string that should be returned after modification. Here's the code
public string InsertSpaceBetweenLetters(int spaceWidth)
{
Contract.Requires(spaceWidth > 0);
Contract.Requires(S.Length > 0);
Contract.Ensures(Contract.Result<string>() != null);
Contract.Ensures(Contract.Result<string>().Length == S.Length + (S.Length - 1) * spaceWidth);
string result = String.Empty;
Contract.Assume(S.Length >= 0);
for(int i = 0; i < S.Length; i++)
{
result += S[i];
if (i < S.Length - 1)
result += new String(' ', spaceWidth);
}
return result;
}
The static checker gives me the following warning:
ensures unproven: Contract.Result<string>().Length == S.Length + (S.Length - 1) * spaceWidth
I thought I could get rid of this warning with the assumption I'm doing before the loop:
Contract.Assume(S.Length >= 0);
But the warning is still there. What assumptions have to be made to get rid of the warning?
Thank you in advance.