Skip to content

Commit 982577c

Browse files
committed
Use old defined g several times
1 parent 27189ea commit 982577c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tutorial/OldAndOrdering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ Some of these have been already discussed; others are discussed in later lessons
2929
There is no pre-defined order to the clauses within a single specification case (cf. a later lesson on [multiple specification cases](MultipleBehaviors)].
3030
However, a specification is much more readable if the clauses generally follow the order above, with preconditions first, then frame conditions, followed by postconditions.
3131

32-
There is some meaning to the ordering within the precondition group and within the postcondition group: earlier clauses can set conditions that are needed for later clauses to be well-defined; but ordering only matters within the kinds of precondition clauses and separately for any `ensures` clauses. For example,
32+
There is some meaning to the ordering within the precondition group and within the postcondition group: earlier clauses can set conditions that are needed for later clauses to be well-defined; but ordering only matters within the each kinds of clause; that is ordering matters within the set of precondition clauses and separately for any `ensures` clauses. For example,
3333
```
3434
{% include_relative T_order1.java %}
3535
```
3636
yields
3737
```
3838
{% include_relative T_order1.out %}
3939
```
40-
The first requires clause might not be well-defined because `a` might be null. If we reverse the order of the clauses, then OpenJML is content:
40+
The first requires clause might not be well-defined because `a` might be null. If we reverse the order of the clauses, as in the following specification, then the method verifies:
4141
```
4242
{% include_relative T_order2.java %}
4343
```

tutorial/T_Old.java

100644100755
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ public class T_Old {
33

44
//@ requires x > 0 && y > 0;
55
//@ old \bigint g = Math.gcd(x,y); // spec from Math library
6-
//@ ensures \result == g;
6+
//@ requires g+g+g <= Integer.MAX_VALUE;
7+
//@ ensures \result == g+g+g;
78
public int myGCD(int x, int y) {
89
// some code
9-
return 0; // placeholder
10+
int g = mygcd(x,y);
11+
return g+g+g;
12+
}
13+
14+
//@ requires x > 0 && y > 0;
15+
//@ old \bigint g = Math.gcd(x,y); // spec from Math library
16+
//@ requires g+g+g <= Integer.MAX_VALUE;
17+
//@ ensures \result == Math.gcd(x,y); // spec from Math library
18+
//@ pure
19+
public int mygcd(int x, int y) {
20+
return 0; // placeholder
1021
}
1122
}

0 commit comments

Comments
 (0)