find(c: CHARACTER; position: INTEGER): INTEGER
This feature finds a character by starting at position i and searching. Once it finds the index it outputs it. However if no such character exists in the word then 0 is output
Question: The postcondition must assert that the query returns the index of a character c in word in range pos .. word.count, or zero if there is no such character.
My Code:
find(c: CHARACTER; position: INTEGER): INTEGER
require
.....
do
.....
ensure
across word as w
some
(w.item = c and w.cursor_index >= position)
end
end
Problem with this boolean equality is that when find(c,pos) is used and nothing is found the feature throws a post-condition violation.
I'm trying to make it allow the feature to output ONLY when the given c character does not exist in the word