Best Assertj code snippet using org.assertj.core.api.AbstractFloatArrayAssert.usingComparatorWithPrecision
Source:AbstractFloatArrayAssert.java
...74 /**75 * Verifies that the actual array contains the given values, in any order.76 * <p>77 * If you want to set a precision for the comparison either use {@link #contains(float[], Offset)} 78 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 79 * <p>80 * Examples :81 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};82 * 83 * // assertions will pass84 * assertThat(values).contains(1.0f, 3.0f, 2.0f)85 * .contains(3.0f, 1.0f)86 * .usingComparatorWithPrecision(0.5f)87 * .contains(1.1f, 2.1f);88 * 89 * // assertions will fail90 * assertThat(values).contains(1.0f, 4.0f);91 * assertThat(values).usingComparatorWithPrecision(0.01f)92 * .contains(1.1f, 2.1f);</code></pre>93 * 94 * @param values the given values.95 * @return {@code this} assertion object.96 * @throws NullPointerException if the given argument is {@code null}.97 * @throws IllegalArgumentException if the given argument is an empty array.98 * @throws AssertionError if the actual array is {@code null}.99 * @throws AssertionError if the actual array does not contain the given values.100 */101 public S contains(float... values) {102 arrays.assertContains(info, actual, values);103 return myself;104 }105 /**106 * Verifies that the actual array contains the given values, in any order, 107 * the comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.108 * <p>109 * Examples :110 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};111 * 112 * // assertion will pass113 * assertThat(values).contains(new float[] {1.01f, 3.01f, 2.0f}, withPrecision(0.02f));114 *115 * // assertions will fail116 * assertThat(values).contains(new float[] {1.0f, 4.0f}, withPrecision(0.5f));117 * assertThat(values).contains(new float[] {4.0f, 7.0f}, withPrecision(2f));</code></pre>118 *119 * @param values the given values.120 * @param precision the precision under which the values may vary.121 * @return {@code this} assertion object.122 * @throws NullPointerException if the given argument is {@code null}.123 * @throws IllegalArgumentException if the given argument is an empty array.124 * @throws AssertionError if the actual array is {@code null}.125 * @throws AssertionError if the actual array does not contain the given values.126 */127 public S contains(float[] values, Offset<Float> precision) {128 usingComparatorWithPrecision(precision.value);129 return contains(values);130 }131 /**132 * Verifies that the actual array contains only the given values and nothing else, in any order.133 * <p>134 * If you want to set a precision for the comparison either use {@link #containsOnly(float[], Offset)} 135 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 136 * <p>137 * Examples :138 * <pre><code class='java'> float[] values = new double[] {1.0f, 2.0f, 3.0f};139 * 140 * // assertions will pass141 * assertThat(values).containsOnly(1.0f, 2.0f, 3.0f)142 * .containsOnly(2.0f, 3.0f, 1.0f)143 * .usingComparatorWithPrecision(0.5f)144 * .containsOnly(1.1f, 3.1f, 2.1f);145 146 * // assertions will fail147 * assertThat(values).containsOnly(1.0f, 4.0f, 2.0f, 3.0f);148 * assertThat(values).containsOnly(4.0f, 7.0f);149 * assertThat(values).containsOnly(1.1f, 2.1f, 3.1f);150 * assertThat(values).usingComparatorWithPrecision(0.01f)151 * .containsOnly(1.1f, 2.1f, 3.1)f;</code></pre>152 * 153 * @param values the given values.154 * @return {@code this} assertion object.155 * @throws NullPointerException if the given argument is {@code null}.156 * @throws IllegalArgumentException if the given argument is an empty array.157 * @throws AssertionError if the actual array is {@code null}.158 * @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some159 * or none of the given values, or the actual array contains more values than the given ones.160 */161 public S containsOnly(float... values) {162 arrays.assertContainsOnly(info, actual, values);163 return myself;164 }165 /**166 * Verifies that the actual array contains only the given values and nothing else, in any order.167 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.168 * <p>169 * Examples :170 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};171 * 172 * // assertion will pass173 * assertThat(values).containsOnly(new float[] {1.0f, 2.0f, 3.0f }, withPrecision(0.00001f))174 * .containsOnly(new float[] {2.0,f 3.0f, 0.7f}, withPrecision(0.5f));175 *176 * // assertions will fail177 * assertThat(values).containsOnly(new float[] {1.0f, 4.0f, 2.0f, 3.0f}, withPrecision(0.5f));178 * assertThat(values).containsOnly(new float[] {4.0f, 7.0f}, withPrecision(0.2f));</code></pre>179 *180 * @param values the given values.181 * @param precision the precision under which the values may vary.182 * @return {@code this} assertion object.183 * @throws NullPointerException if the given argument is {@code null}.184 * @throws IllegalArgumentException if the given argument is an empty array.185 * @throws AssertionError if the actual array is {@code null}.186 * @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some187 * or none of the given values, or the actual array contains more values than the given ones.188 */189 public S containsOnly(float[] values, Offset<Float> precision) {190 usingComparatorWithPrecision(precision.value);191 return containsOnly(values);192 }193 /**194 * Verifies that the actual array contains the given values only once.195 * <p>196 * If you want to set a precision for the comparison either use {@link #containsOnlyOnce(float[], Offset)} 197 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 198 * <p>199 * Examples :200 * <pre><code class='java'> // assertions will pass201 * assertThat(new float[] { 1.0f, 2.0f, 3.0f }).containsOnlyOnce(1.0f, 2.0f)202 * .usingComparatorWithPrecision(0.5f)203 * .containsOnlyOnce(1.1f, 3.1f, 2.1f);204 * 205 * // assertions will fail206 * assertThat(new float[] { 1.0f, 2.0f, 1.0f }).containsOnlyOnce(1.0f);207 * assertThat(new float[] { 1.0f, 2.0f, 1.0f }).containsOnlyOnce(1.0f, 2.0f);208 * assertThat(new float[] { 1.0f, 2.0f, 3.0f }).containsOnlyOnce(4.0f);209 * assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.05f)210 * .containsOnlyOnce(1.1f, 2.1f);</code></pre>211 * 212 * @param values the given values.213 * @return {@code this} assertion object.214 * @throws NullPointerException if the given argument is {@code null}.215 * @throws IllegalArgumentException if the given argument is an empty array.216 * @throws AssertionError if the actual array is {@code null}.217 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group contains some218 * or none of the given values, or the actual group contains more than once these values.219 */220 public S containsOnlyOnce(float... values) {221 arrays.assertContainsOnlyOnce(info, actual, values);222 return myself;223 }224 /**225 * Verifies that the actual array contains the given values only once.226 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.227 * <p>228 * Examples :229 * <pre><code class='java'> // assertion will pass230 * assertThat(new float[] { 1.0f, 2.0f, 3.0f }).containsOnlyOnce(new float[] {1.1f, 2.0f}, withPrecision(0.2f));231 *232 * // assertions will fail233 * assertThat(new float[] { 1.0f, 2.0f, 1.0f }).containsOnlyOnce(new float[] {1.05f}, withPrecision(0.1f));234 * assertThat(new float[] { 1.0f, 2.0f, 3.0f }).containsOnlyOnce(new float[] {4.0f}, withPrecision(0.1f));235 * assertThat(new float[] { 1.0f, 2.0f, 3.0f, 3.0f }).containsOnlyOnce(new float[] {0.1f, 0.9f, 2.0f, 3.11f, 4.0f, 5.0f}, withPrecision(0.2f));</code></pre>236 *237 * @param values the given values.238 * @param precision the precision under which the values may vary.239 * @return {@code this} assertion object.240 * @throws NullPointerException if the given argument is {@code null}.241 * @throws IllegalArgumentException if the given argument is an empty array.242 * @throws AssertionError if the actual array is {@code null}.243 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group contains some244 * or none of the given values, or the actual group contains more than once these values.245 */246 public S containsOnlyOnce(float[] values, Offset<Float> precision) {247 usingComparatorWithPrecision(precision.value);248 return containsOnlyOnce(values);249 }250 /**251 * Verifies that the actual array contains the given sequence, without any other values between them.252 * <p>253 * If you want to set a precision for the comparison either use {@link #containsSequence(float[], Offset)} 254 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 255 * <p>256 * Examples :257 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };258 * 259 * // assertion will pass260 * assertThat(values).containsSequence(1.0f, 2.0f)261 * .containsSequence(1.0f, 2.0f, 3.0f)262 * .containsSequence(2.0f, 3.0f)263 * .usingComparatorWithPrecision(0.5f)264 * .containsSequence(1.1f, 2.1f);265 * 266 * // assertions will fail267 * assertThat(values).containsSequence(1.0f, 3.0f);268 * assertThat(values).containsSequence(4.0f, 7.0f);269 * assertThat(values).usingComparatorWithPrecision(0.01f)270 * .containsSequence(1.1f, 2.0f, 3.0f);</code></pre>271 * 272 * @param sequence the sequence of values to look for.273 * @return {@code this} assertion object.274 * @throws AssertionError if the actual array is {@code null}.275 * @throws AssertionError if the given array is {@code null}.276 * @throws AssertionError if the actual array does not contain the given sequence.277 */278 public S containsSequence(float... sequence) {279 arrays.assertContainsSequence(info, actual, sequence);280 return myself;281 }282 /**283 * Verifies that the actual array contains the given sequence, without any other values between them.284 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.285 * <p>286 * Examples :287 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};288 * 289 * // assertions will pass290 * assertThat(values).containsSequence(new float[] {1.07f, 2.0f}, withPrecision(0.1f))291 * .containsSequence(new float[] {1.1f, 2.1f, 3.0f}, withPrecision(0.2f))292 * .containsSequence(new float[] {2.2f, 3.0f}, withPrecision(0.3f));293 *294 * // assertions will fail295 * assertThat(values).containsSequence(new float[] {1.0f, 3.0f}, withPrecision(0.2f));296 * assertThat(values).containsSequence(new float[] {4.0f, 7.0f}, withPrecision(0.1f));</code></pre>297 *298 * @param sequence the sequence of values to look for.299 * @param precision the precision under which the values may vary.300 * @return {@code this} assertion object.301 * @throws AssertionError if the actual array is {@code null}.302 * @throws AssertionError if the given array is {@code null}.303 * @throws AssertionError if the actual array does not contain the given sequence.304 */305 public S containsSequence(float[] sequence, Offset<Float> precision) {306 usingComparatorWithPrecision(precision.value);307 return containsSequence(sequence);308 }309 /**310 * Verifies that the actual array contains the given subsequence (possibly with other values between them).311 * <p>312 * If you want to set a precision for the comparison either use {@link #containsSubsequence(float[], Offset)} 313 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 314 * <p>315 * Examples :316 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };317 * 318 * // assertion will pass319 * assertThat(values).containsSubsequence(1.0f, 2.0f);320 * .containsSubsequence(1.0f, 2.0f, 3.0f)321 * .containsSubsequence(1.0f, 3.0f)322 * .usingComparatorWithPrecision(0.5f)323 * .containsSubsequence(1.1f, 2.1f);324 * 325 * // assertions will fail326 * assertThat(values).containsSubsequence(3.0f, 1.0f);327 * assertThat(values).containsSubsequence(4.0f, 7.0f);328 * assertThat(values).usingComparatorWithPrecision(0.01f)329 * .containsSubsequence(1.1f, 2.0f);</code></pre>330 * 331 * @param subsequence the subsequence of values to look for.332 * @return {@code this} assertion object.333 * @throws AssertionError if the actual array is {@code null}.334 * @throws AssertionError if the given array is {@code null}.335 * @throws AssertionError if the actual array does not contain the given subsequence.336 */337 public S containsSubsequence(float... subsequence) {338 arrays.assertContainsSubsequence(info, actual, subsequence);339 return myself;340 }341 /**342 * Verifies that the actual array contains the given subsequence (possibly with other values between them).343 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.344 * <p>345 * Examples :346 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};347 * 348 * // assertions will pass349 * assertThat(values).containsSubsequence(new float[] {1.0f, 2.0f}, withPrecision(0.1f))350 * .containsSubsequence(new float[] {1.0f, 2.07f, 3.0f}, withPrecision(0.1f))351 * .containsSubsequence(new float[] {2.1f, 2.9f}, withPrecision(0.2f));352 *353 * // assertions will fail354 * assertThat(values).containsSubsequence(new float[] {1.0f, 3.0f}, withPrecision(0.1f));355 * assertThat(values).containsSubsequence(new float[] {4.0f, 7.0f}, withPrecision(0.1f));</code></pre>356 *357 * @param subsequence the subsequence of values to look for.358 * @param precision the precision under which the values may vary.359 * @return {@code this} assertion object.360 * @throws AssertionError if the actual array is {@code null}.361 * @throws AssertionError if the given array is {@code null}.362 * @throws AssertionError if the actual array does not contain the given subsequence.363 */364 public S containsSubsequence(float[] subsequence, Offset<Float> precision) {365 usingComparatorWithPrecision(precision.value);366 return containsSubsequence(subsequence);367 }368 /**369 * Verifies that the actual array contains the given value at the given index.370 * <p>371 * If you want to set a precision for the comparison either use {@link #contains(float, Index, Offset)} 372 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 373 * <p>374 * Example:375 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };376 * 377 * // assertion will pass378 * assertThat(values).contains(1.0f, atIndex(O))379 * .contains(3.0f, atIndex(2))380 * .usingComparatorWithPrecision(0.5f)381 * .contains(3.1f, atIndex(2));382 * 383 * // assertions will fail384 * assertThat(values).contains(1.0f, atIndex(1));385 * assertThat(values).contains(4.0f, atIndex(2));386 * assertThat(values).usingComparatorWithPrecision(0.01f)387 * .contains(3.1f, atIndex(2));</code></pre>388 * 389 * @param value the value to look for.390 * @param index the index where the value should be stored in the actual array.391 * @return {@code this} assertion object.392 * @throws AssertionError if the actual array is {@code null} or empty.393 * @throws NullPointerException if the given {@code Index} is {@code null}.394 * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of395 * the actual array.396 * @throws AssertionError if the actual array does not contain the given value at the given index.397 */398 public S contains(float value, Index index) {399 arrays.assertContains(info, actual, value, index);400 return myself;401 }402 /**403 * Verifies that the actual array contains the given value at the given index.404 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.405 * <p>406 * Example:407 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};408 * 409 * // assertions will pass410 * assertThat(values).contains(1.0f, atIndex(O), withPrecision(0.01f))411 * .contains(3.3f, atIndex(2), withPrecision(0.5f));412 *413 * // assertions will fail414 * assertThat(values).contains(1.0f, atIndex(1), withPrecision(0.2f));415 * assertThat(values).contains(4.5f, atIndex(2), withPrecision(0.1f));</code></pre>416 *417 * @param value the value to look for.418 * @param index the index where the value should be stored in the actual array.419 * @param precision the precision which the value may vary.420 * @return {@code this} assertion object.421 * @throws AssertionError if the actual array is {@code null} or empty.422 * @throws NullPointerException if the given {@code Index} is {@code null}.423 * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of424 * the actual array.425 * @throws AssertionError if the actual array does not contain the given value at the given index.426 */427 public S contains(float value, Index index, Offset<Float> precision) {428 usingComparatorWithPrecision(precision.value);429 return contains(value, index);430 }431 /**432 * Verifies that the actual array does not contain the given values.433 * <p>434 * If you want to set a precision for the comparison either use {@link #doesNotContain(float[], Offset)} 435 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 436 * <p>437 * Example:438 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };439 * 440 * // assertion will pass441 * assertThat(values).doesNotContain(4.0f, 8.0f)442 * .usingComparatorWithPrecision(0.0001f)443 * .doesNotContain(1.01f, 2.01f);444 * 445 * // assertions will fail446 * assertThat(values).doesNotContain(1.0f, 4.0f, 8.0f);447 * assertThat(values).usingComparatorWithPrecision(0.1f)448 * .doesNotContain(1.001f, 2.001f);</code></pre>449 * 450 * @param values the given values.451 * @return {@code this} assertion object.452 * @throws NullPointerException if the given argument is {@code null}.453 * @throws IllegalArgumentException if the given argument is an empty array.454 * @throws AssertionError if the actual array is {@code null}.455 * @throws AssertionError if the actual array contains any of the given values.456 */457 public S doesNotContain(float... values) {458 arrays.assertDoesNotContain(info, actual, values);459 return myself;460 }461 /**462 * Verifies that the actual array does not contain the given values.463 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.464 * <p>465 * Example:466 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};467 * 468 * // assertion will pass469 * assertThat(values).doesNotContain(new float[] {4.0f, 8.0f}, withPrecision(0.5f));470 *471 * // assertion will fail472 * assertThat(values).doesNotContain(new float[] {1.05f, 4.0f, 8.0f}, withPrecision(0.1f));</code></pre>473 *474 * @param values the given values.475 * @param precision the precision under which the values may vary.476 * @return {@code this} assertion object.477 * @throws NullPointerException if the given argument is {@code null}.478 * @throws IllegalArgumentException if the given argument is an empty array.479 * @throws AssertionError if the actual array is {@code null}.480 * @throws AssertionError if the actual array contains any of the given values.481 */482 public S doesNotContain(float[] values, Offset<Float> precision) {483 usingComparatorWithPrecision(precision.value);484 arrays.assertDoesNotContain(info, actual, values);485 return myself;486 }487 /**488 * Verifies that the actual array does not contain the given value at the given index.489 * <p>490 * If you want to set a precision for the comparison either use {@link #doesNotContain(float, Index, Offset)} 491 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 492 * <p>493 * Example:494 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };495 * 496 * // assertion will pass497 * assertThat(values).doesNotContain(1.0f, atIndex(1))498 * .doesNotContain(2.0f, atIndex(0))499 * .usingComparatorWithPrecision(0.001)500 * .doesNotContain(1.1f, atIndex(0));501 * 502 * // assertions will fail503 * assertThat(values).doesNotContain(1.0f, atIndex(0));504 * assertThat(values).usingComparatorWithPrecision(0.1)505 * .doesNotContain(1.001f, atIndex(0));</code></pre>506 * 507 * @param value the value to look for.508 * @param index the index where the value should be stored in the actual array.509 * @return {@code this} assertion object.510 * @throws AssertionError if the actual array is {@code null}.511 * @throws NullPointerException if the given {@code Index} is {@code null}.512 * @throws AssertionError if the actual array contains the given value at the given index.513 */514 public S doesNotContain(float value, Index index) {515 arrays.assertDoesNotContain(info, actual, value, index);516 return myself;517 }518 /**519 * Verifies that the actual array does not contain the given value at the given index.520 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.521 * <p>522 * Example:523 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};524 * 525 * // assertions will pass526 * assertThat(values).doesNotContain(1.01f, atIndex(1), withPrecision(0.0001f))527 * .doesNotContain(2.05f, atIndex(0), withPrecision(0.1f));528 *529 * // assertion will fail530 * assertThat(values).doesNotContain(1.01f, atIndex(0), withPrecision(0.1f));</code></pre>531 *532 * @param value the value to look for.533 * @param index the index where the value should be stored in the actual array.534 * @param precision the precision under which the value may vary.535 * @return {@code this} assertion object.536 * @throws AssertionError if the actual array is {@code null}.537 * @throws NullPointerException if the given {@code Index} is {@code null}.538 * @throws AssertionError if the actual array contains the given value at the given index.539 */540 public S doesNotContain(float value, Index index, Offset<Float> precision) {541 usingComparatorWithPrecision(precision.value);542 return doesNotContain(value, index);543 }544 /**545 * Verifies that the actual array does not contain duplicates.546 * <p>547 * If you want to set a precision for the comparison either use {@link #doesNotHaveDuplicates(Offset)} 548 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 549 * <p>550 * Example:551 * <pre><code class='java'> // assertions will pass552 * assertThat(new float[] { 1.0f, 2.0f, 3.0f }).doesNotHaveDuplicates();553 * assertThat(new float[] { 1.0f, 1.1f }).usingComparatorWithPrecision(0.01f)554 * .doesNotHaveDuplicates();555 * 556 * // assertions will fail557 * assertThat(new float[] { 1.0f, 1.0f, 2.0f, 3.0f }).doesNotHaveDuplicates();558 * assertThat(new float[] { 1.0f, 1.1f }).usingComparatorWithPrecision(0.5f)559 * .doesNotHaveDuplicates();</code></pre>560 * 561 * @return {@code this} assertion object.562 * @throws AssertionError if the actual array is {@code null}.563 * @throws AssertionError if the actual array contains duplicates.564 */565 public S doesNotHaveDuplicates() {566 arrays.assertDoesNotHaveDuplicates(info, actual);567 return myself;568 }569 /**570 * Verifies that the actual array does not contain duplicates.571 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.572 * <p>573 * Example:574 * <pre><code class='java'> // assertions will pass575 * assertThat(new float[] {1.0f, 2.0f, 3.0f}).doesNotHaveDuplicates(withPrecision(0.1f));576 * assertThat(new float[] {1.1f, 1.2f, 1.3f}).doesNotHaveDuplicates(withPrecision(0.05f));577 * 578 * // assertion will fail579 * assertThat(new float[] {1.0f, 1.01f, 2.0f}).doesNotHaveDuplicates(withPrecision(0.1f));</code></pre>580 * 581 * @param precision the precision under which the values may vary.582 * @return {@code this} assertion object.583 * @throws AssertionError if the actual array is {@code null}.584 * @throws AssertionError if the actual array contains duplicates.585 */586 public S doesNotHaveDuplicates(Offset<Float> precision) {587 usingComparatorWithPrecision(precision.value);588 return doesNotHaveDuplicates();589 }590 /**591 * Verifies that the actual array starts with the given sequence of values, without any other values between them.592 * Similar to <code>{@link #containsSequence(float...)}</code>, but it also verifies that the first element in the593 * sequence is also first element of the actual array.594 * <p>595 * If you want to set a precision for the comparison either use {@link #startsWith(float[], Offset)} 596 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 597 * <p>598 * Example:599 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };600 * 601 * // assertion will pass602 * assertThat(values).startsWith(1.0f, 2.0f)603 * .usingComparatorWithPrecision(0.5f)604 * .startsWith(1.1f, 2.1f);605 * 606 * // assertion will fail607 * assertThat(values).startsWith(2.0f, 3.0f);</code></pre>608 * 609 * @param sequence the sequence of values to look for.610 * @return {@code this} assertion object.611 * @throws NullPointerException if the given argument is {@code null}.612 * @throws IllegalArgumentException if the given argument is an empty array.613 * @throws AssertionError if the actual array is {@code null}.614 * @throws AssertionError if the actual array does not start with the given sequence.615 */616 public S startsWith(float... sequence) {617 arrays.assertStartsWith(info, actual, sequence);618 return myself;619 }620 /**621 * Verifies that the actual array starts with the given sequence of values, without any other values between them.622 * Similar to <code>{@link #containsSequence(float...)}</code>, but it also verifies that the first element in the623 * sequence is also first element of the actual array.624 * <p>625 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.626 * <p>627 * Example:628 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};629 * 630 * // assertion will pass631 * assertThat(values).startsWith(new float[] {1.01f, 2.01f}, withPrecision(0.1f));632 * 633 * // assertions will fail634 * assertThat(values).startsWith(new float[] {2.0f, 1.0f}, withPrecision(0.1f))635 * assertThat(values).startsWith(new float[] {1.1f, 2.1f}, withPrecision(0.5f))</code></pre>636 * 637 * @param sequence the sequence of values to look for.638 * @param precision the precision under which the values may vary.639 * @return {@code this} assertion object.640 * @throws NullPointerException if the given argument is {@code null}.641 * @throws IllegalArgumentException if the given argument is an empty array.642 * @throws AssertionError if the actual array is {@code null}.643 * @throws AssertionError if the actual array does not end with the given sequence.644 */645 public S startsWith(float[] values, Offset<Float> precision) {646 usingComparatorWithPrecision(precision.value);647 return startsWith(values);648 }649 /**650 * Verifies that the actual array ends with the given sequence of values, without any other values between them.651 * Similar to <code>{@link #containsSequence(float...)}</code>, but it also verifies that the last element in the652 * sequence is also last element of the actual array.653 * <p>654 * If you want to set a precision for the comparison either use {@link #endsWith(float[], Offset)} 655 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 656 * <p>657 * Example:658 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };659 * 660 * // assertion will pass661 * assertThat(values).endsWith(2.0f, 3.0f)662 * .usingComparatorWithPrecision(0.5f)663 * .endsWith(2.1f, 3.1f);664 * 665 * // assertion will fail666 * assertThat(values).endsWith(1.0f, 3.0f);</code></pre>667 * 668 * @param sequence the sequence of values to look for.669 * @return {@code this} assertion object.670 * @throws NullPointerException if the given argument is {@code null}.671 * @throws IllegalArgumentException if the given argument is an empty array.672 * @throws AssertionError if the actual array is {@code null}.673 * @throws AssertionError if the actual array does not end with the given sequence.674 */675 public S endsWith(float... sequence) {676 arrays.assertEndsWith(info, actual, sequence);677 return myself;678 }679 /**680 * Verifies that the actual array ends with the given sequence of values, without any other values between them.681 * Similar to <code>{@link #containsSequence(float...)}</code>, but it also verifies that the last element in the682 * sequence is also last element of the actual array.683 * <p>684 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Float)}.685 * <p>686 * Example:687 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};688 * 689 * // assertion will pass690 * assertThat(values).endsWith(new float[] {2.01f, 3.01f}, withPrecision(0.1f));691 * 692 * // assertions will fail693 * assertThat(values).endsWith(new float[] {3.0f, 2.0f}, withPrecision(0.1f))694 * assertThat(values).endsWith(new float[] {2.1f, 3.1f}, withPrecision(0.5f))</code></pre>695 * 696 * @param sequence the sequence of values to look for.697 * @param precision the precision under which the values may vary.698 * @return {@code this} assertion object.699 * @throws NullPointerException if the given argument is {@code null}.700 * @throws IllegalArgumentException if the given argument is an empty array.701 * @throws AssertionError if the actual array is {@code null}.702 * @throws AssertionError if the actual array does not end with the given sequence.703 */704 public S endsWith(float[] values, Offset<Float> precision) {705 usingComparatorWithPrecision(precision.value);706 return endsWith(values);707 }708 /** {@inheritDoc} */709 @Override710 public S isSorted() {711 arrays.assertIsSorted(info, actual);712 return myself;713 }714 /** {@inheritDoc} */715 @Override716 public S isSortedAccordingTo(Comparator<? super Float> comparator) {717 arrays.assertIsSortedAccordingToComparator(info, actual, comparator);718 return myself;719 }720 /** {@inheritDoc} */721 @Override722 public S usingElementComparator(Comparator<? super Float> customComparator) {723 this.arrays = new FloatArrays(new ComparatorBasedComparisonStrategy(customComparator));724 return myself;725 }726 /** {@inheritDoc} */727 @Override728 public S usingDefaultElementComparator() {729 this.arrays = FloatArrays.instance();730 return myself;731 }732 /**733 * Verifies that the actual group contains only the given values and nothing else, <b>in order</b>.734 * <p>735 * If you want to set a precision for the comparison either use {@link #containsExactly(float[], Offset)} 736 * or {@link #usingComparatorWithPrecision(Float)} before calling the assertion. 737 * <p>738 * Example :739 * <pre><code class='java'> float[] values = new float[] { 1.0f, 2.0f, 3.0f };740 * 741 * // assertion will pass742 * assertThat(values).containsExactly(1.0f, 2.0f, 3.0f)743 * .usingComparatorWithPrecision(0.2f)744 * .containsExactly(1.1f, 2.1f, 2.9f);745 * 746 * // assertion will fail as actual and expected orders differ747 * assertThat(values).containsExactly(2.0f, 1.0f, 3.0f);</code></pre>748 * 749 * @param values the given values.750 * @return {@code this} assertion object.751 * @throws NullPointerException if the given argument is {@code null}.752 * @throws AssertionError if the actual group is {@code null}.753 * @throws AssertionError if the actual group does not contain the given values with same order, i.e. the actual group754 * contains some or none of the given values, or the actual group contains more values than the given ones755 * or values are the same but the order is not.756 */757 public S containsExactly(float... values) {758 arrays.assertContainsExactly(info, actual, values);759 return myself;760 }761 /**762 * Verifies that the actual group contains only the given values and nothing else, <b>in order</b>.763 * The values may vary with a specified precision.764 * <p>765 * Example :766 * <pre><code class='java'> float[] values = new float[] {1.0f, 2.0f, 3.0f};767 * 768 * // assertion will pass769 * assertThat(values).containsExactly(new float[] {1.0f, 1.98f, 3.01f}, withPrecision(0.05f));770 *771 * // assertion fails because |1.0 - 1.1| > 0.05 (precision)772 * assertThat(values).containsExactly(new float[] {1.1f, 2.0f, 3.01f}, withPrecision(0.05f));773 * 774 * // assertion will fail as actual and expected orders differ775 * assertThat(values).containsExactly(new float[] {1.98f, 1.0f, 3.01f}, withPrecision(0.05f));</code></pre>776 *777 * @param values the given values.778 * @param precision the precision under which the values may vary.779 * @return {@code this} assertion object.780 * @throws NullPointerException if the given argument is {@code null}.781 * @throws AssertionError if the actual group is {@code null}.782 * @throws AssertionError if the actual group does not contain the given values within the specified precision 783 * with same order, i.e. the actual group contains some or none of the given values, or the actual group contains 784 * more values than the given ones or values are the same but the order is not.785 */786 public S containsExactly(float[] values, Offset<Float> precision) {787 usingComparatorWithPrecision(precision.value);788 return containsExactly(values);789 }790 /**791 * Create a {@link Float} comparator which compares floats at the given precision and pass it to {@link #usingElementComparator(Comparator)}. 792 * All the following assertions will use this comparator to compare float[] elements.793 * 794 * @param precision precisin used to compare {@link Float}.795 * @return {@code this} assertion object.796 */797 public S usingComparatorWithPrecision(Float precision) {798 return usingElementComparator(floatComparator.floatComparatorWithPrecision(precision));799 }800}...
usingComparatorWithPrecision
Using AI Code Generation
1import org.assertj.core.api.AbstractFloatArrayAssert;2import org.assertj.core.api.AbstractDoubleArrayAssert;3import org.assertj.core.api.AbstractFloatAssert;4import org.assertj.core.api.AbstractDoubleAssert;5import org.assertj.core.api.AbstractBigDecimalAssert;6import org.assertj.core.api.AbstractBigIntegerAssert;7import org.assertj.core.api.AbstractLongAssert;8import org.assertj.core.api.AbstractIntegerAssert;9import org.assertj.core.api.AbstractShortAssert;10import org.assertj.core.api.AbstractByteAssert;11import org.assertj.core.api.AbstractFloatArrayAssert;12import org.assertj.core.api.AbstractDoubleArrayAssert;13import java.math.BigDecimal;14import java.math.BigInteger;15public class UsingComparatorWithPrecision {16 public static void main(String[] args) {17 AbstractFloatArrayAssert<?> abstractFloatArrayAssert;18 AbstractDoubleArrayAssert<?> abstractDoubleArrayAssert;19 AbstractFloatAssert<?> abstractFloatAssert;20 AbstractDoubleAssert<?> abstractDoubleAssert;21 AbstractBigDecimalAssert<?> abstractBigDecimalAssert;22 AbstractBigIntegerAssert<?> abstractBigIntegerAssert;23 AbstractLongAssert<?> abstractLongAssert;24 AbstractIntegerAssert<?> abstractIntegerAssert;25 AbstractShortAssert<?> abstractShortAssert;26 AbstractByteAssert<?> abstractByteAssert;27 AbstractFloatArrayAssert<?> abstractFloatArrayAssert;28 AbstractDoubleArrayAssert<?> abstractDoubleArrayAssert;29 }30}
usingComparatorWithPrecision
Using AI Code Generation
1assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).contains(1.1f, 2.2f, 3.3f);2assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsOnly(1.1f, 2.2f, 3.3f);3assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsExactly(1.1f, 2.2f, 3.3f);4assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsExactlyInAnyOrder(1.1f, 2.2f, 3.3f);5assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsExactlyInAnyOrderElementsOf(Arrays.asList(1.1f, 2.2f, 3.3f));6assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsSequence(1.1f, 2.2f);7assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsSubsequence(1.1f, 2.2f, 3.3f);8assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsOnlyOnce(1.1f, 2.2f, 3.3f);9assertThat(new float[] { 1.0f, 2.0f, 3.0f }).usingComparatorWithPrecision(0.1f).containsAnyOf(1.1f, 2.2f, 3.3f);10assertThat(new float[] {
usingComparatorWithPrecision
Using AI Code Generation
1Float[] actual = {1.1f, 2.2f, 3.3f};2Float[] expected = {1.2f, 2.3f, 3.4f};3assertThat(actual).usingComparatorWithPrecision(0.1f).isEqualTo(expected);4Float[] actual = {1.1f, 2.2f, 3.3f};5Float[] expected = {1.2f, 2.3f, 3.4f};6assertThat(actual).usingComparatorWithPrecision(0.1f).isEqualTo(expected);7Float[] actual = {1.1f, 2.2f, 3.3f};8Float[] expected = {1.2f, 2.3f, 3.4f};9assertThat(actual).usingComparatorWithPrecision(0.1f).isEqualTo(expected);10Float[] actual = {1.1f, 2.2f, 3.3f};11Float[] expected = {1.2f, 2.3f, 3.4f};12assertThat(actual).usingComparatorWithPrecision(0.1f).isEqualTo(expected);13Float[] actual = {1.1f, 2.2f, 3.3f};14Float[] expected = {1.2f, 2.3f, 3.4f};15assertThat(actual).usingComparatorWithPrecision(0.1f).isEqualTo(expected);16Float[] actual = {1.1f, 2.2f, 3.3f};17Float[] expected = {1.2f, 2.3f, 3.4f};18assertThat(actual).usingComparatorWithPrecision(0.1f).isEqualTo(expected);19Float[] actual = {1.1f, 2.2f, 3
usingComparatorWithPrecision
Using AI Code Generation
1import org.assertj.core.api.AbstractFloatArrayAssert;2import org.assertj.core.api.Assertions;3public class AssertjDemo {4 public static void main(String[] args) {5 float[] array1 = {1.1f, 2.2f, 3.3f};6 float[] array2 = {1.11f, 2.22f, 3.33f};7 AbstractFloatArrayAssert<?> assertions = Assertions.assertThat(array1);8 assertions.usingComparatorWithPrecision(0.01f).isEqualTo(array2);9 }10}11but found the following difference(s):12Related posts: AssertJ – How to use usingComparatorWithPrecision() method to compare two float arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two double arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two short arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two long arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two int arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two char arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two byte arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two object arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two boolean arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two arrays AssertJ – How to use usingComparatorWithPrecision() method to compare two arrays AssertJ – How to use usingComparatorWithPrecision
usingComparatorWithPrecision
Using AI Code Generation
1import org.assertj.core.api.AbstractFloatArrayAssert;2public class AbstractFloatArrayAssert_use_usingComparatorWithPrecision_Test {3 public static void main(String[] args) {4 AbstractFloatArrayAssert<?> assertions = Assertions.assertThat(new float[]{1.0f, 2.0f});5 assertions.usingComparatorWithPrecision(0.5f).contains(1.0f, 2.0f);6 }7}8org.assertj.core.api.AbstractFloatArrayAssertBase<org.assertj.core.api.AbstractFloatArrayAssert<?>> usingComparatorWithPrecision(java.lang.Float)
usingComparatorWithPrecision
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import org.junit.Test;3public class AssertJFloatArrayAssertUsingComparatorWithPrecisionExample {4 public void usingComparatorWithPrecisionExample() {5 float[] actual = new float[]{1.0f, 2.0f, 3.0f, 4.0f};6 float[] expected = new float[]{1.1f, 2.1f, 3.1f, 4.1f};7 assertThat(actual).usingComparatorWithPrecision(0.2f)8 .containsExactly(expected);9 }10}11at org.junit.Assert.assertEquals(Assert.java:115)12at org.junit.Assert.assertEquals(Assert.java:144)13at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:82)14at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:86)15at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:35)16at org.assertj.core.api.AssertionsForClassTypes.assertThat(AssertionsForClassTypes.java:69)17at org.assertj.core.api.Assertions.assertThat(Assertions.java:823)18at com.baeldung.assertj.FloatArrayAssertExamples.usingComparatorWithPrecisionExample(FloatArrayAssertExamples.java:57)
usingComparatorWithPrecision
Using AI Code Generation
1public void usingComparatorWithPrecision() {2 float[] array1 = new float[] { 1.0f, 2.0f, 3.0f };3 float[] array2 = new float[] { 1.1f, 2.1f, 3.1f };4 assertThat(array1).usingComparatorWithPrecision(0.1f).contains(array2);5}6public void usingComparatorWithPrecision() {7 float[] array1 = new float[] { 1.0f, 2.0f, 3.0f };8 float[] array2 = new float[] { 1.1f, 2.1f, 3.1f };9 assertThat(array1).usingComparatorWithPrecision(0.1f).contains(array2);10}11public void usingComparatorWithPrecision() {12 float[] array1 = new float[] { 1.0f, 2.0f, 3.0f };13 float[] array2 = new float[] { 1.1f, 2.1f, 3.1f };14 assertThat(array1).usingComparatorWithPrecision(0.1f).contains(array2);15}16public void usingComparatorWithPrecision() {17 float[] array1 = new float[] { 1.0f, 2.0f, 3.0f };18 float[] array2 = new float[] { 1.1f, 2.1f, 3.1f };19 assertThat(array1).usingComparatorWithPrecision(0.1f).contains(array2);20}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!