I am trying to write pre and post conditions to find the maximum value of a collection ‘col’. I’m not really sure how to go about it, recursively so I was wondering if someone could help!
pre: true
post: result = ...
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What I would do:
EDIT2: I discussed this question with some OCL experts. They pointed out that it’s necessary to have
col -> includes(result)in the post condition. Otherwiseresultmay be any value greater than all elements ofcol, but is not necessarily an element ofcol.EDIT:
The post condition means: for each element
aofcol, it is true thata <= resultThe
forAlloperation is defined on page 45 of the OCL Specification 2.3.1. Its syntax isIts semantics is:
This forAll expression results in a Boolean. The result is true if the boolean-expression is true for all elements of
collection. If the boolean-expression-with-v is false for one or more v in collection, then the complete expression
evaluates to false. For example, in the context of a company:
Examples: