Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:36:46+00:00 2026-06-16T19:36:46+00:00

I am trying to write pre and post conditions to find the maximum value

  • 0

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 = ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:36:47+00:00Added an answer on June 16, 2026 at 7:36 pm

    What I would do:

    pre:  not col.isEmpty()
    post: col -> includes(result) and col -> forAll(a | a <= result)
    

    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. Otherwise result may be any value greater than all elements of col, but is not necessarily an element of col.

    EDIT:

    The post condition means: for each element a of col, it is true that a <= result
    The forAll operation is defined on page 45 of the OCL Specification 2.3.1. Its syntax is

    collection->forAll( v | boolean-expression-with-v )
    

    Its 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:

     context Company
          inv: self.employee->forAll( age <= 65 )
          inv: self.employee->forAll( p | p.age <= 65 )
          inv: self.employee->forAll( p : Person | p.age <= 65 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a unit test for my :pre and :post conditions,
been trying to find out if there is a way to pre-write the tag
I'm trying to write a new jQuery plugin. base (this is not my plugin,
I'm trying to write a blog post which includes a code segment inside a
I am trying to write a pre-commit hook script that will alter a specific
I've been trying to write a script to pre-process some long lists of files,
I'm trying to write a Git pre-commit hook script. It should write the date
I'm trying to write a method that will take in two Queues (pre-sorted Linked
I've been trying to write data back to a pre-defined plist file (data.plist) in
In trying to write a pre-receive hook which rejects certain kinds of changes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.