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
3
votes
0 answers

How to mark aws data pipeline as FINISHED not ERROR when s3 precondition fails?

I've been struggling for a few weeks to find a config solution that works how I expect - maybe what I want isn't possible... Here's what I'm trying to do: Check an S3 bucket for any files If there aren't any, don't spin up a cluster just mark the…
3
votes
2 answers

Validating a string for a positive number, null/empty string

I have a method in which I am accepting a String clientid and that has below requirements: clientid can be a positive number greater than zero. But if it is negative number or zero, then throw IllegalArgumentException with a message. clientid…
user1950349
  • 4,738
  • 19
  • 67
  • 119
3
votes
1 answer

Clojure :pre report failing value when destructuring

Following this SO post, I would like to print the value of the preconditions in my function. However it fails for me in the following case (probably destructuring) : I have a dir? helper function (feel free to skip this one) : (defn dir? [s] …
nha
  • 17,623
  • 13
  • 87
  • 133
3
votes
5 answers

Java: weak pre condition and strong post condition, how to?

I'm having a really hard time in understanding how pre-conditions and post-conditions must work, without violate the Substitution Principle. So let's assume that we have a class Rectangle and Square—how to relate them? Which one must be the…
Francesco
  • 521
  • 1
  • 6
  • 14
3
votes
1 answer

Should client check postcondition/should called method check precondition?

The preconditions and the postconditions of the public method form a contract between this method and its client. 1.According to, caller shouldn't verify postcondition and called method shouldn't verify preconditions: Let us recall the precondition…
EdvRusj
  • 745
  • 7
  • 14
3
votes
6 answers

Binary Searching

So, I want to understand more about binary searching, cause I don't really understand. Binary search requires a precondition that an array is sorted. I got that right? It seems like a method should check this precondition and throw an exception if…
Sam
  • 111
  • 1
  • 2
  • 9
3
votes
5 answers

c++ preconditions/assertions

This is not my homework -- I'm just practicing. I can't seem to wrap my mind around this assertion concept. 1) Determine the pre-condition for x that guarantees the post-condition about y { _______ } if (x > 0) y = x; else y = -x; { y >= 0…
erbisme4
  • 31
  • 4
3
votes
12 answers

preconditions and exceptions

Suppose you have a method with some pre and post-conditions. Is it ok to create an exception class for each pre-condition that is not accomplished? For example: Not accomplishing pre1 means throwing a notPre1Exception instance.
Lucia
  • 4,657
  • 6
  • 43
  • 57
3
votes
1 answer

Liquibase precondition for unique constraint

I want to add a unique constraint to a column using Liquibase. Of course I want to check if duplicate rows exist using a precondition. I came up this: select count(*) from person …
siebz0r
  • 18,867
  • 14
  • 64
  • 107
2
votes
2 answers

Code Contracts 1.4.40602.0 - Contract.ForAll doesn't seem to be working?

Warning 1 CodeContracts: requires unproven: Contract.ForAll(coll, item => item != null) C:\MyApp\MyObj.cs public MyObj() : this(new Collection()) { } public MyObj(ICollection coll) { …
myermian
  • 31,823
  • 24
  • 123
  • 215
2
votes
2 answers

can I use a Junit Test as a precondition For another Junit Test

I have a jUnit test (lets call it T1) in which I use an assertion. For that assertion to be of any value I need the validator for that assertion to be correct. For the validator I have a test (T2) in another test Suite. Can I somehow make T2 a…
Rythmic
  • 759
  • 2
  • 10
  • 25
2
votes
1 answer

Automatic conversion of wrapper in C#

I've build wrapper-class intended to prevent reference types of being null, as a pre-condition code contract. public sealed class NotNullable where T : class { private T t; public static implicit operator NotNullable(T otherT) …
philipshield
  • 303
  • 2
  • 8
2
votes
1 answer

Is there a way to require a particular value as a parameter in an abstract Interface method in Java?

I'm writing a little functional Interface and the method that it contains, takes an int as parameter. I was wondering if there's any way to check that when this method will be called, the value passed to the method, will not exceed a certain value…
motelepf
  • 27
  • 5
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

dafny pre-condition failure

I'm trying to run a dafny verified version of BFS (from here) My input graph is perfectly fine, but for some reason it fails the pre-condition check. Here is the permalink And for self completeness here is the graph definition + validity…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87