-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.in
63 lines (51 loc) · 1.9 KB
/
README.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
## jaffirm
The `jaffirm` package provides simple and fast pre/postcondition and invariant
checking functions.
## Features
* Static invocation, zero-allocation code paths for the common case of non-failing contracts.
* Specialized and generic variants of all functions for use in low-latency software.
* Detailed contract failure messages by construction.
* Written in pure Java 17.
* High coverage test suite.
* [OSGi-ready](https://www.osgi.org/)
* [JPMS-ready](https://en.wikipedia.org/wiki/Java_Platform_Module_System)
* ISC license.
## Usage
Declare preconditions with the `Preconditions` class.
Declare postconditions with the `Postconditions` class.
Declare invariants with the `Invariants` class.
```
import static com.io7m.jaffirm.core.Contracts.conditionI;
import static com.io7m.jaffirm.core.Preconditions.checkPreconditionI;
import static com.io7m.jaffirm.core.Preconditions.checkPreconditionsI;
int exampleSingles(final int x)
{
checkPreconditionI(x, x > 0, i -> "Input " + i + " must be > 0");
checkPreconditionI(x, x % 2 == 0, i -> "Input " + i + " must be even");
return x * 2;
}
int exampleMultis(final int x)
{
checkPreconditionsI(
x,
conditionI(i -> i > 0, i -> "Input " + i + " must be > 0"),
conditionI(i -> i % 2 == 0, i -> "Input " + i + " must be even"));
return x * 2;
}
> exampleSingles(0)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
Received: 0
Violated conditions:
[0]: Input 0 must be > 0
> exampleSingles(1)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
Received: 1
Violated conditions:
[0]: Input 1 must be even
> exampleMultis(-1)
Exception in thread "main" com.io7m.jaffirm.core.PreconditionViolationException: Precondition violation.
Received: -1
Violated conditions:
[0]: Input -1 must be > 0
[1]: Input -1 must be even
```