A postcondition is some condition which must be satisfied after running a given section of code. It may be specified in code via assertions, or in the documentation.
Questions tagged [post-conditions]
58 questions
1
vote
1 answer
How to travse a linked list in my postcodition use across loop in Eiffel?
I try to use
across 1|..|list.count as j
all
list.i_th(z) ~ old list.i_th(z)
end
but it says unknown identifier z. Whats wrong with this syntax??

buzzmind
- 109
- 2
- 10
1
vote
2 answers
Effective Eiffel Postcondition for Ensuring that Array is sorted
I have implemented a query that tells if array is sorted or not. I want to make a good postcondition that will effectively check if array is sorted using across or something else.
I tried to do this like this:
is_sorted (a: ARRAY [INTEGER]):…

Dragos Strugar
- 1,314
- 3
- 12
- 30
1
vote
3 answers
Is "A requirement that should be satisfied by the function before it ends." a right definition for postcondition, in Python?
In "Think Python: How to Think Like a Computer Scientist", the author defines postcondition as:
A requirement that should be satisfied by the function before it ends.
He also states:
Conversely, conditions at the end of the function are…

Mahmood Muhammad Nageeb
- 434
- 5
- 16
1
vote
1 answer
Is an exception a valid postcondition?
Consider the following interface:
public interface AISPI
{
public Path getPath(Entity entity, Entity target, World world) throws NoPathException;
}
Granted that entity, target, and world are all valid input. But the algorithm used to find a…

LuqJensen
- 310
- 6
- 14
1
vote
1 answer
Subprogram contracts in Ada
I'm reading a document on Ada programming to be more specific, Ada for C++ Java developer, or I'm in trouble and to understand and be able to use some of the examples given in the document, one of them is on pre- and postconditions
But, when I…

Alexandre
- 1,985
- 5
- 30
- 55
1
vote
1 answer
why is CodeContracts static checker suggesting that I Contract.Assume(a) right after I Contract.Ensure(a)?
Basically, I have a virtual method to propagate certain mandatory postconditions to subclasses. Here's a simplified version and the strange warnings the static checker generates (edit - my example was incomplete. It's right now):
public abstract…

user2212990
- 177
- 1
- 9
1
vote
4 answers
OCL: How can I write pre and postconditions for the operation max to find the maximum value from a collection?
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 = ...

mark
- 2,841
- 4
- 25
- 23
0
votes
1 answer
program written in dafny, implementing the Merge Sorted Arrays in-Place algorithm
Here is the program that given to me in dafny:
method Main() {
var a, b := new int[3] [3,5,8], new int[2] [4,7];
print "Before merging the following two sorted arrays:\n";
print a[..];
print "\n";
print b[..];
ghost var AB :=…

kimpatz
- 1
- 1
0
votes
1 answer
Sort and switch methods in Dafny (Invariants error)
I am new to Dafny and wrote two methods, switch and sort. In sort I get an error in line 10 and 12 and in switch in line 24 and 26. Both based on the forall invaraiants. I'm struggling and can't figure out why.
The error messages I'm getting are…

TRASHeaven
- 5
- 1
0
votes
1 answer
Weak precondition and strong postcondition problems?
in last exam, I've had question, I was unable to answer sanely.
Question was "what problems might arise from too weak precondition?"
Another question was "what problems might arise from too strong postcondtition?"
How to go about answering that…

Timo Junolainen
- 294
- 2
- 13
0
votes
1 answer
(Dafny) Postcondition might not hold when filtering vowels
I'm studying for my Dafny exam and I don't know what's wrong with my code.
I think it has something to do with my "index out of range" error but I don't know how to solve that.
Any hints would be greatly appreciated.
The problem:
Given an array of…

Irfan Zainudin
- 55
- 4
- 11
0
votes
2 answers
Postcondition of a method with mypy
I have a mutable object which I populate with data. Once all the mandatory data is present, the object can be “committed”. Attempting to commit an incomplete object raises an exception. Here's a toy example with an object whose content is initially…

Gilles 'SO- stop being evil'
- 104,111
- 38
- 209
- 254
0
votes
1 answer
How do I get a true value when using object_comparison on an empty linked list in my post condition?
I have an assignment that requires me to create an empty linked list key: LINKED_LIST [KEY], another linked list data_items_1: LINKED_LIST [DATA1] and a hash table data_items_2: HASH_TABLE [DATA2, KEY] in the constructor. The post condition that my…

Ed Shirinian
- 25
- 6
0
votes
1 answer
How do I use an across loop in post condition to compare an old array and new array at certain indices?
I have a method that shifts all the items, in an array, to the left by one position. In my post condition I need to ensure that my items have shifted to the left by one. I have already compared the first element of the old array to the last element…

Ed Shirinian
- 25
- 6
0
votes
2 answers
Tool/Technique for Automatic Unit Test Generation based on Method Pre-/Post-Conditions
I wonder if there is any tool that automatically generates unit tests based on a method's pre- and post-conditions (and class invariant).
To be precise, suppose we are given pre- and post-conditions (and probably class invariant) for a method and we…

RealNamesOrHandles
- 17
- 1
- 6