Questions tagged [preconditions]

A precondition is some condition which must be satisfied before running a given section of code. It may be specified in code via assertions, or in the documentation.

If a precondition is violated, errors or security issues may occur. A precondition states what is required for the section of code to run correctly.

Links

Related tags

166 questions
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 :=…
0
votes
1 answer

Can Java compiler optimisation cause Google Guava's Preconditions checks to be ignored?

We have a POJO in our Java application let's say Request which has validateRequest() method that basically validates some of it's fields using Guava's Preconditions library. So, Basically Class looks like this : public class Request { private…
0
votes
1 answer

Axiomatic Semantics - How to calculate a weakest precondition of a program

Assuming the post-condition, how can I compute the weakest pre-condition of a program containing two statements? For example : a=x; y = 0 {x = y + a} Another example: y = x; y = x + x + y {y = 3x ^ z> 0} I tried to solve them but both…
Raghad
  • 55
  • 5
0
votes
0 answers

Java preconditions about class variables

i have a question about preconditions. I have this code. public class NetModel() { private Net net = null; public NetModel() {} public void setNet(Net net) { this.net = net; } /** * @param netName the name…
Stefano
  • 13
  • 5
0
votes
2 answers

Stop pytest right at the start if condition not met

Any way of stopping the entire pytest run from happening at a very early stage if some condition is not met. For example, if it is found that the Elasticsearch service is not running? I have tried putting this in a common file which is imported by…
mike rodent
  • 14,126
  • 11
  • 103
  • 157
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…
0
votes
1 answer

C++ ensure object exists while executing a function

I have a function foo. During the execution of foo, I want to be certain that an object of type Bar exists. Let’s call whatever object that happens to be “bar.” I cannot copy or move bar, and bar can have any storage duration. The one thing I do…
nebuch
  • 6,475
  • 4
  • 20
  • 39
0
votes
1 answer

Java: Is There Any Way to Specify When an Exception Will be Thrown?

I have code something like this pseudo code: void doSomething(int data) throws Exception{ if(data < 10) throw new Exception("Exception thrown"); // throws an exception based on a condition else { ... } // logic goes here } When I try to…
Captain Hatteras
  • 490
  • 3
  • 11
0
votes
1 answer

how to use a precondition check to stop next line from executing (or for whatever other reason it might be used for)

Like if I had an else if or try catch statement. How can I stop specific lines of code from executing if the statement failed or caught an unhandled exception I already posted the question before, so I'm just reformulating. If you don't want the…
0
votes
1 answer

Dafny precondition checks in generated code

I was wondering if there is a way to add precondition checks in the Dafny generated code. For example, let's take the following code snippet: method MultipleReturns(x: int, y: int) returns (more: int, less: int) requires 0 < y ensures less < x…
0
votes
1 answer

How to use precondition to ensure that the inputs are of type int only

Let say I have a function that return the lesser of two input values of type int. I want to set the precondition to only allow a and b of type int. class Example functions min: int * int -> int min(a, b) == if a < b then a …
a..
  • 109
  • 13
0
votes
1 answer

Timeout while proving the WP using Alt-ergo on Frama C

I was trying to verify the correctness of the below program using Frama-c.I am new user to frama-C. PROBLEM: Input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic…
Niresh
  • 67
  • 7
0
votes
1 answer

Should an exception be thrown or should the method simply return?

I am currently wondering about what is "best" to do if null is passed to the following method. Should it silently return (as it does no) or should it throw an exception instead? public void RaisePropertyChanged(string propertyName) { …
Thomas Flinkow
  • 4,845
  • 5
  • 29
  • 65
0
votes
2 answers

pddl precondtion not working correctly in the plan

I am working on a project in pddl. The idea is to pick four balls and transfer them to the conveyer. (defined in the goal) The simple pickup, move and drop actions work fine but when I try to make it more complicated for eg. by adding different…
0
votes
1 answer

Frama-c: How to justify variadic argument with va_list and va_arg?

Currently, I am using Frama-C version 19, and struggling with variadic arguments. For example) #include #include void vars2(int n, va_list args) { for (size_t i = 0; i < n; ++i) { int tmp = va_arg(args,…