27
27
import org .jspecify .annotations .Nullable ;
28
28
29
29
/**
30
- * Propositions for {@link Double} subjects .
30
+ * Propositions for {@link Double} values .
31
31
*
32
32
* @author Kurt Alfred Kluever
33
33
*/
@@ -40,18 +40,18 @@ private DoubleSubject(FailureMetadata metadata, @Nullable Double actual) {
40
40
}
41
41
42
42
/**
43
- * A partially specified check about an approximate relationship to a {@code double} subject using
44
- * a tolerance.
43
+ * A partially specified check about an approximate relationship to a {@code double} value using a
44
+ * tolerance.
45
45
*/
46
46
public abstract static class TolerantDoubleComparison {
47
47
48
48
// Prevent subclassing outside of this class
49
49
private TolerantDoubleComparison () {}
50
50
51
51
/**
52
- * Fails if the subject was expected to be within the tolerance of the given value but was not
53
- * <i>or</i> if it was expected <i>not</i> to be within the tolerance but was. The subject and
54
- * tolerance are specified earlier in the fluent call chain.
52
+ * Fails if the actual value was expected to be within the tolerance of the given value but was
53
+ * not <i>or</i> if it was expected <i>not</i> to be within the tolerance but was. The actual
54
+ * value and tolerance are specified earlier in the fluent call chain.
55
55
*/
56
56
public abstract void of (double expected );
57
57
@@ -79,13 +79,13 @@ public int hashCode() {
79
79
}
80
80
81
81
/**
82
- * Prepares for a check that the subject is a finite number within the given tolerance of an
82
+ * Prepares for a check that the actual value is a finite number within the given tolerance of an
83
83
* expected value that will be provided in the next call in the fluent chain.
84
84
*
85
- * <p>The check will fail if either the subject or the object is {@link Double#POSITIVE_INFINITY},
86
- * {@link Double#NEGATIVE_INFINITY}, or {@link Double#NaN}. To check for those values, use {@link
87
- * #isPositiveInfinity}, {@link #isNegativeInfinity}, {@link #isNaN}, or (with more generality)
88
- * {@link #isEqualTo}.
85
+ * <p>The check will fail if either the actual value or the expected value is {@link
86
+ * Double#POSITIVE_INFINITY}, {@link Double#NEGATIVE_INFINITY}, or {@link Double#NaN}. To check
87
+ * for those values, use {@link #isPositiveInfinity}, {@link #isNegativeInfinity}, {@link #isNaN},
88
+ * or (with more generality) {@link #isEqualTo}.
89
89
*
90
90
* <p>The check will pass if both values are zero, even if one is {@code 0.0} and the other is
91
91
* {@code -0.0}. Use {@link #isEqualTo} to assert that a value is exactly {@code 0.0} or that it
@@ -96,9 +96,9 @@ public int hashCode() {
96
96
* and {@code -0.0}). See the documentation on {@link #isEqualTo} for advice on when exact
97
97
* equality assertions are appropriate.
98
98
*
99
- * @param tolerance an inclusive upper bound on the difference between the subject and object
100
- * allowed by the check, which must be a non-negative finite value, i.e. not {@link
101
- * Double#NaN}, {@link Double#POSITIVE_INFINITY}, or negative, including {@code -0.0}
99
+ * @param tolerance an inclusive upper bound on the difference between the actual value and
100
+ * expected value allowed by the check, which must be a non-negative finite value, i.e. not
101
+ * {@link Double#NaN}, {@link Double#POSITIVE_INFINITY}, or negative, including {@code -0.0}
102
102
*/
103
103
public TolerantDoubleComparison isWithin (double tolerance ) {
104
104
return new TolerantDoubleComparison () {
@@ -120,12 +120,12 @@ public void of(double expected) {
120
120
}
121
121
122
122
/**
123
- * Prepares for a check that the subject is a finite number not within the given tolerance of an
124
- * expected value that will be provided in the next call in the fluent chain.
123
+ * Prepares for a check that the actual value is a finite number not within the given tolerance of
124
+ * an expected value that will be provided in the next call in the fluent chain.
125
125
*
126
- * <p>The check will fail if either the subject or the object is {@link Double#POSITIVE_INFINITY},
127
- * {@link Double#NEGATIVE_INFINITY}, or {@link Double#NaN}. See {@link #isFinite}, {@link
128
- * #isNotNaN}, or {@link #isNotEqualTo} for checks with other behaviours.
126
+ * <p>The check will fail if either the actual value or the expected value is {@link
127
+ * Double#POSITIVE_INFINITY}, {@link Double#NEGATIVE_INFINITY}, or {@link Double#NaN}. See {@link
128
+ * #isFinite}, {@link # isNotNaN}, or {@link #isNotEqualTo} for checks with other behaviours.
129
129
*
130
130
* <p>The check will fail if both values are zero, even if one is {@code 0.0} and the other is
131
131
* {@code -0.0}. Use {@link #isNotEqualTo} for a test which fails for a value of exactly zero with
@@ -135,9 +135,9 @@ public void of(double expected) {
135
135
* but sometimes {@link #isNotEqualTo} is preferable (note the different behaviours around
136
136
* non-finite values and {@code -0.0}).
137
137
*
138
- * @param tolerance an exclusive lower bound on the difference between the subject and object
139
- * allowed by the check, which must be a non-negative finite value, i.e. not {@code
140
- * Double.NaN}, {@code Double.POSITIVE_INFINITY}, or negative, including {@code -0.0}
138
+ * @param tolerance an exclusive lower bound on the difference between the actual value and
139
+ * expected value allowed by the check, which must be a non-negative finite value, i.e. not
140
+ * {@code Double.NaN}, {@code Double.POSITIVE_INFINITY}, or negative, including {@code -0.0}
141
141
*/
142
142
public TolerantDoubleComparison isNotWithin (double tolerance ) {
143
143
return new TolerantDoubleComparison () {
@@ -159,7 +159,7 @@ public void of(double expected) {
159
159
}
160
160
161
161
/**
162
- * Asserts that the subject is exactly equal to the given value, with equality defined as by
162
+ * Asserts that the actual value is exactly equal to the given value, with equality defined as by
163
163
* {@code Double#equals}. This method is <i>not</i> recommended when the code under test is doing
164
164
* any kind of arithmetic: use {@link #isWithin} with a suitable tolerance in that case. (Remember
165
165
* that the exact result of floating point arithmetic is sensitive to apparently trivial changes
@@ -179,9 +179,9 @@ public void isEqualTo(@Nullable Object other) {
179
179
}
180
180
181
181
/**
182
- * Asserts that the subject is not exactly equal to the given value, with equality defined as by
183
- * {@code Double#equals}. See {@link #isEqualTo} for advice on when exact equality is recommended.
184
- * Use {@link #isNotWithin} for an assertion with a tolerance.
182
+ * Asserts that the actual value is not exactly equal to the given value, with equality defined as
183
+ * by {@code Double#equals}. See {@link #isEqualTo} for advice on when exact equality is
184
+ * recommended. Use {@link #isNotWithin} for an assertion with a tolerance.
185
185
*
186
186
* <p><b>Note:</b> The assertion {@code isNotEqualTo(0.0)} passes for {@code -0.0}, and vice
187
187
* versa. For an assertion that fails for either {@code 0.0} or {@code -0.0}, use {@link
@@ -201,15 +201,15 @@ public void isEquivalentAccordingToCompareTo(@Nullable Double other) {
201
201
super .isEquivalentAccordingToCompareTo (other );
202
202
}
203
203
204
- /** Asserts that the subject is zero (i.e. it is either {@code 0.0} or {@code -0.0}). */
204
+ /** Asserts that the actual value is zero (i.e. it is either {@code 0.0} or {@code -0.0}). */
205
205
public void isZero () {
206
206
if (actual == null || actual != 0.0 ) {
207
207
failWithActual (simpleFact ("expected zero" ));
208
208
}
209
209
}
210
210
211
211
/**
212
- * Asserts that the subject is a non-null value other than zero (i.e. it is not {@code 0.0},
212
+ * Asserts that the actual value is a non-null value other than zero (i.e. it is not {@code 0.0},
213
213
* {@code -0.0} or {@code null}).
214
214
*/
215
215
public void isNonZero () {
@@ -220,23 +220,23 @@ public void isNonZero() {
220
220
}
221
221
}
222
222
223
- /** Asserts that the subject is {@link Double#POSITIVE_INFINITY}. */
223
+ /** Asserts that the actual value is {@link Double#POSITIVE_INFINITY}. */
224
224
public void isPositiveInfinity () {
225
225
isEqualTo (Double .POSITIVE_INFINITY );
226
226
}
227
227
228
- /** Asserts that the subject is {@link Double#NEGATIVE_INFINITY}. */
228
+ /** Asserts that the actual value is {@link Double#NEGATIVE_INFINITY}. */
229
229
public void isNegativeInfinity () {
230
230
isEqualTo (Double .NEGATIVE_INFINITY );
231
231
}
232
232
233
- /** Asserts that the subject is {@link Double#NaN}. */
233
+ /** Asserts that the actual value is {@link Double#NaN}. */
234
234
public void isNaN () {
235
235
isEqualTo (NaN );
236
236
}
237
237
238
238
/**
239
- * Asserts that the subject is finite, i.e. not {@link Double#POSITIVE_INFINITY}, {@link
239
+ * Asserts that the actual value is finite, i.e. not {@link Double#POSITIVE_INFINITY}, {@link
240
240
* Double#NEGATIVE_INFINITY}, or {@link Double#NaN}.
241
241
*/
242
242
public void isFinite () {
@@ -246,7 +246,7 @@ public void isFinite() {
246
246
}
247
247
248
248
/**
249
- * Asserts that the subject is a non-null value other than {@link Double#NaN} (but it may be
249
+ * Asserts that the actual value is a non-null value other than {@link Double#NaN} (but it may be
250
250
* {@link Double#POSITIVE_INFINITY} or {@link Double#NEGATIVE_INFINITY}).
251
251
*/
252
252
public void isNotNaN () {
@@ -258,39 +258,39 @@ public void isNotNaN() {
258
258
}
259
259
260
260
/**
261
- * Checks that the subject is greater than {@code other}.
261
+ * Checks that the actual value is greater than {@code other}.
262
262
*
263
- * <p>To check that the subject is greater than <i>or equal to</i> {@code other}, use {@link
263
+ * <p>To check that the actual value is greater than <i>or equal to</i> {@code other}, use {@link
264
264
* #isAtLeast}.
265
265
*/
266
266
public void isGreaterThan (int other ) {
267
267
isGreaterThan ((double ) other );
268
268
}
269
269
270
270
/**
271
- * Checks that the subject is less than {@code other}.
271
+ * Checks that the actual value is less than {@code other}.
272
272
*
273
- * <p>To check that the subject is less than <i>or equal to</i> {@code other}, use {@link
273
+ * <p>To check that the actual value is less than <i>or equal to</i> {@code other}, use {@link
274
274
* #isAtMost} .
275
275
*/
276
276
public void isLessThan (int other ) {
277
277
isLessThan ((double ) other );
278
278
}
279
279
280
280
/**
281
- * Checks that the subject is less than or equal to {@code other}.
281
+ * Checks that the actual value is less than or equal to {@code other}.
282
282
*
283
- * <p>To check that the subject is <i>strictly</i> less than {@code other}, use {@link
283
+ * <p>To check that the actual value is <i>strictly</i> less than {@code other}, use {@link
284
284
* #isLessThan}.
285
285
*/
286
286
public void isAtMost (int other ) {
287
287
isAtMost ((double ) other );
288
288
}
289
289
290
290
/**
291
- * Checks that the subject is greater than or equal to {@code other}.
291
+ * Checks that the actual value is greater than or equal to {@code other}.
292
292
*
293
- * <p>To check that the subject is <i>strictly</i> greater than {@code other}, use {@link
293
+ * <p>To check that the actual value is <i>strictly</i> greater than {@code other}, use {@link
294
294
* #isGreaterThan}.
295
295
*/
296
296
public void isAtLeast (int other ) {
0 commit comments