Guest User

Untitled

a guest
Jun 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. booger (master)$ cat examples/example3.rb
  2. class Stack
  3. # @modifies @elements
  4. # @modifies @size
  5. def initialize
  6. @size = 0
  7. # @elements = [] (array assignment not yet supported)
  8. end
  9.  
  10. # @modifies @elements
  11. # @modifies @size
  12. # @ensures @size == old(@size) + 1
  13. def push(element)
  14. @size = @size + 1
  15. @elements.push element
  16. end
  17.  
  18. # @modifies @size
  19. # @requires @size > 0
  20. # @ensures @size == old(@size) - 1
  21. def pop
  22. @size = @size - 1
  23. @elements.pop
  24. end
  25. end
  26.  
  27. def use
  28. stack = Stack.new
  29. stack.pop
  30. end
  31.  
  32. booger (master)$ ./bin/booger examples/example3.rb
  33. Verification Errors (2):
  34.  
  35. - A precondition for this call might not hold:31:
  36. stack.pop
  37.  
  38. - This is the precondition that might not hold:
  39. @requires @size > 0
Add Comment
Please, Sign In to add comment