Guest User

Untitled

a guest
May 21st, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. [ContractInvariantMethod]
  2. private void ObjectInvariant()
  3. {
  4. Contract.Invariant(count >= 0 && count <= buffer.Length);
  5. for (int i = count; i < buffer.Length; i++)
  6. {
  7. Contract.Invariant(buffer[i] == null);
  8. }
  9. for (int i = 1; i < count; i++)
  10. {
  11. Contract.Invariant(string.Compare(buffer[i], buffer[i - 1]) >= 0);
  12. }
  13. }
  14.  
  15. Contract.Invariant(count >= 0 && count <= buffer.Length);
  16. Contract.Invariant(Contract.ForAll
  17. (count, buffer.Length, i => buffer[i] == null));
  18. Contract.Invariant(Contract.ForAll
  19. (1, count, i => string.Compare(buffer[i], buffer[i - 1]) >= 0));
  20.  
  21. //untested
  22. Contract.Invariant(Contract.ForAll(count, buffer.Length, i => buffer[i] == null));
  23. Contract.Invariant(Contract.ForAll(1, count,
  24. i => string.Compare(buffer[i], buffer[i - 1]) >= 0));
  25.  
  26. bool Invariant() const; // in C++, mimicking Eiffel
  27.  
  28. private bool Invariant()
  29. {
  30. // All the logic, function returns true if object is valid i.e. function
  31. // simply will never return false, in the absence of a bug
  32. }
  33. // Good old invariant in C#, no special attributes, just a function
  34.  
  35. [ContractInvariantMethod]
  36. private void ObjectInvariant()
  37. {
  38. Contract.Invariant(Invariant() == true);
  39. }
  40.  
  41. Contract.Invariant(IsValid);
Add Comment
Please, Sign In to add comment