Questions tagged [post-conditions]

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.

Links

Related tags

58 questions
2
votes
0 answers

How can i assign a new value to a function parameter in an ada postcondition

i've been trying a lot of things and looking for solutions but i can't find one. I' m stuck because i need to assign a new value to a post condition in an ada function For example, with the following function: function Square(A: in out INTEGER)…
2
votes
1 answer

How to give the right precondition to prove an assert statemnt in frama-c?

I have been working on some basic programs in c to verify using the frama-c tool.I wanted to know why the assertion is not being proved in the program.Thanks in advance. #include /*@requires \valid(a) && \valid(b) && \separated(a,b); …
Niresh
  • 67
  • 7
2
votes
1 answer

Custom condition failure messages in Ada 2012

Is there a way to specify a custom error/on failure message for pre- and postconditions, by analogy with Predicate_Failure for predicates? I can't seem to be able to find anything in the official documentation. TIA.
2
votes
1 answer

ADA - pre and post conditions not working?

I am trying to learn on my own pre and post conditions in ada.
catrev
  • 85
  • 7
2
votes
1 answer

Why is the existential necessary in strongest postconditions?

Every formulation of the strongest postcondition predicate transformer I have seen presents the assignment rule as follows: sp(X:=E, P) = ∃v. (X=E[v/X] ∧ P[v/X]) I am wondering, why is the existential (and thus the existentially quantified variable…
2
votes
2 answers

Debugging in Java with preconditions

Working with Chromium codebase I got used to macros like CHECK(condition);, DCHECK(contidtion) and NOTREACHED;. They introduce assertions (usually preconditions) to the code and allow to terminate program with some info in a log, an in debug build…
Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64
2
votes
3 answers

Explanation of Pre-conditions and Post-Conditions?

My latest assignment requires me to have this follow criteria "All methods have explicit postcondition and those with parameters preconditions " I have read through a few web pages trying to explain pre/post conditions, but can seem to get a…
user3496101
  • 303
  • 1
  • 6
  • 14
2
votes
1 answer

Proving correctness of algorithm

I was wondering if anyone could help me answer this question. It is from a previous exam paper and I could do with knowing the answer ready for this years exam. This question seems so simple that I am getting completely lost, what exactly is it…
2
votes
3 answers

Can an OCL Post condition be inside an if then statement?

I'm new to OCL and I have some doubts about how the pre and postconditions work. Can a post condition be placed inside an if then statement? For example, the following piece of code is valid or I'm just mixing concepts? Context [some context…
droca
  • 45
  • 3
  • 9
2
votes
5 answers

Pre-condition vs Post-condition in java?

For example I have the following code: public class Calc(){ final int PI = 3.14; //is this an invariant? private int calc(int a, int b){ return a + b; //would the parameters be pre-conditions and the return value be a…
user2708074
1
vote
1 answer

Neo4js conditional information storage

I am new to graph database and stuck with the following issue. I'm trying to store below conditional information in the graph. when a=1 and b=2 then sum=3, when a=2 and b=3 then sum=5 and mul=6 Here there are 4 pre-conditions[(a=1, b=2),(a=2,…
1
vote
1 answer

Strengthening and Weakening of pre and post conditions

I have been reading into the topic of Design By Contract and so far have the following notes written: When strengthening a condition, it means to make it more restrictive and weakening a condition is the opposite. A subclass' pre-condition is…
1
vote
2 answers

How can I fix this code with unstoppable loop?

I am going to make a funny quiz random the 3 questions and giving 3 chances to guess. After I tried to execute, I tried the correct answer but keep looping and tell my answer is incorrect and can't stop looping and I have no idea why.... Can anyone…
Doris Ng
  • 13
  • 2
1
vote
1 answer

dafny assertion fails is hard to explain

I'm trying to prove the correctness of a method that determines whether a sequence of size n is a permutation of 0,1,...,n-1. I managed to prove that whenever the method returns true then the sequence is indeed a valid permutation. Still, proving…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
1
vote
1 answer

Hoare Logic | What post-condition is valid when there is an infinite loop?

My teacher told me the following statement is valid: {x > 3} while true (x := 3) {x = 3} Why is this statement valid? Is it because the post-condition never gets checked, or will the post-condition now count as an invariant check? In short: can the…
ToTheMax
  • 981
  • 8
  • 18