-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCorrectOperatorAssignments.java
More file actions
88 lines (73 loc) · 1.77 KB
/
CorrectOperatorAssignments.java
File metadata and controls
88 lines (73 loc) · 1.77 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package testSuite;
import liquidjava.specification.Refinement;
public class CorrectOperatorAssignments {
@Refinement("_ > 0")
int plus(@Refinement("_ >= 0") int x) {
x += 1; // x is now > 0
return x;
}
@Refinement("_ > 0")
int plusInvocation(@Refinement("_ >= 0") int x) {
x += one(); // x is now > 0
return x;
}
@Refinement("_ == 1")
int one() {
return 1;
}
@Refinement("_ < 0")
int minus(@Refinement("_ <= 0") int x) {
x -= 1; // x is now < 0
return x;
}
@Refinement("_ >= 0")
int multiply(int x) {
x *= x; // x is now >= 0
return x;
}
@Refinement("_ <= 1")
int divide(@Refinement("0 <= _ && _ <= 3") int x) {
x /= 2; // x is now <= 1
return x;
}
@Refinement("_ == 0 || _ == 1")
int remainder(@Refinement("_ >= 0") int x) {
x %= 2; // x is now == 0 || x is now == 1
return x;
}
int remainderInvocation(@Refinement("_ >= 0") int x) {
@Refinement("_ == 10 || _ == 11")
int y = 10;
y += remainder(x); // x is now >= 6
return x;
}
@Refinement("_ == 9")
int plusUnaryInvocation() {
int y = 10;
y += -one();
return y;
}
@Refinement("_ == 11")
int plusConditional(@Refinement("_ >= 0") int x) {
int y = 10;
y += x >= 0 ? one() : 2;
return y;
}
@Refinement("_ == 13")
int plusBinaryExpression() {
int y = 10;
y += one() + 2;
return y;
}
int plusArrayRead(int[] values) {
int y = 10;
y += values[0];
return y;
}
@Refinement("_ == 11")
int plusCast() {
int y = 10;
y += (int) one();
return y;
}
}