How to use usingComparatorWithPrecision method of org.assertj.core.api.AbstractDoubleArrayAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractDoubleArrayAssert.usingComparatorWithPrecision

Source:AbstractDoubleArrayAssert.java Github

copy

Full Screen

...77 /**78 * Verifies that the actual array contains the given values, in any order.79 * <p>80 * If you want to set a precision for the comparison either use {@link #contains(double[], Offset)} 81 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 82 * <p>83 * Examples :84 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };85 * 86 * // assertion will pass87 * assertThat(values).contains(1.0, 3.0, 2.0)88 * .contains(3.0, 1.0)89 * .usingComparatorWithPrecision(0.5)90 * .contains(1.1, 2.1);91 * 92 * // assertions will fail93 * assertThat(values).contains(1.0, 4.0);94 * assertThat(values).usingComparatorWithPrecision(0.01)95 * .contains(1.1, 2.1);</code></pre>96 * 97 * @param values the given values.98 * @return {@code this} assertion object.99 * @throws NullPointerException if the given argument is {@code null}.100 * @throws IllegalArgumentException if the given argument is an empty array.101 * @throws AssertionError if the actual array is {@code null}.102 * @throws AssertionError if the actual array does not contain the given values.103 */104 public S contains(double... values) {105 arrays.assertContains(info, actual, values);106 return myself;107 }108 /**109 * Verifies that the actual array contains the given values, in any order, 110 * the comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.111 * <p>112 * Examples :113 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };114 * 115 * // assertion will pass116 * assertThat(values).contains(new double[] {1.01, 3.01, 2.0}, withPrecision(0.02));117 *118 * // assertions will fail119 * assertThat(values).contains(new double[] {1.0, 4.0}, withPrecision(0.5));120 * assertThat(values).contains(new double[] {4.0, 7.0}, withPrecision(2));</code></pre>121 *122 * @param values the given values.123 * @param precision the precision under which the value may vary124 * @return {@code this} assertion object.125 * @throws NullPointerException if the given argument is {@code null}.126 * @throws IllegalArgumentException if the given argument is an empty array.127 * @throws AssertionError if the actual array is {@code null}.128 * @throws AssertionError if the actual array does not contain the given values.129 */130 public S contains(double[] values, Offset<Double> precision) {131 usingComparatorWithPrecision(precision.value);132 return contains(values);133 }134 /**135 * Verifies that the actual array contains only the given values and nothing else, in any order.136 * <p>137 * If you want to set a precision for the comparison either use {@link #containsOnly(double[], Offset)} 138 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 139 * <p>140 * Examples :141 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };142 * 143 * // assertion will pass144 * assertThat(values).containsOnly(1.0, 2.0, 3.0)145 * .containsOnly(2.0, 3.0, 1.0)146 * .usingComparatorWithPrecision(0.5)147 * .containsOnly(1.1, 3.1, 2.1);148 * // assertions will fail149 * assertThat(values).containsOnly(1.0, 4.0, 2.0, 3.0);150 * assertThat(values).containsOnly(4.0, 7.0);151 * assertThat(values).containsOnly(1.1, 2.1, 3.1);152 * assertThat(values).usingComparatorWithPrecision(0.01)153 * .containsOnly(1.1, 2.1, 3.1);</code></pre>154 * 155 * </p>156 * 157 * @param values the given values.158 * @return {@code this} assertion object.159 * @throws NullPointerException if the given argument is {@code null}.160 * @throws IllegalArgumentException if the given argument is an empty array.161 * @throws AssertionError if the actual array is {@code null}.162 * @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some163 * or none of the given values, or the actual array contains more values than the given ones.164 */165 public S containsOnly(double... values) {166 arrays.assertContainsOnly(info, actual, values);167 return myself;168 }169 /**170 * Verifies that the actual array contains only the given values and nothing else, in any order.171 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.172 * <p>173 * Examples :174 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };175 * 176 * // assertion will pass177 * assertThat(values).containsOnly(new double[] {1.0, 2.0, 3.0}, withPrecision(0.00001))178 * .containsOnly(new double[] {2.0, 3.0, 0.7}, withPrecision(0.5));179 *180 * // assertions will fail181 * assertThat(values).containsOnly(new double[] {1.0, 4.0, 2.0, 3.0}, withPrecision(0.5));182 * assertThat(values).containsOnly(new double[] {4.0, 7.0}, withPrecision(0.2));</code></pre>183 *184 * </p>185 *186 * @param values the given values.187 * @param precision the precision under which the value may vary188 * @return {@code this} assertion object.189 * @throws NullPointerException if the given argument is {@code null}.190 * @throws IllegalArgumentException if the given argument is an empty array.191 * @throws AssertionError if the actual array is {@code null}.192 * @throws AssertionError if the actual array does not contain the given values, i.e. the actual array contains some193 * or none of the given values, or the actual array contains more values than the given ones.194 */195 public S containsOnly(double[] values, Offset<Double> precision) {196 usingComparatorWithPrecision(precision.value);197 return containsOnly(values);198 }199 /**200 * Verifies that the actual array contains the given values only once.201 * <p>202 * If you want to set a precision for the comparison either use {@link #containsOnlyOnce(double[], Offset)} 203 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 204 * <p>205 * Examples :206 * <pre><code class='java'> // assertion will pass207 * assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(1.0, 2.0)208 * .usingComparatorWithPrecision(0.5)209 * .containsOnlyOnce(1.1, 3.1, 2.1);210 * 211 * // assertions will fail212 * assertThat(new double[] { 1.0, 2.0, 1.0 }).containsOnlyOnce(1.0);213 * assertThat(new double[] { 1.0, 2.0, 1.0 }).containsOnlyOnce(1.0, 2.0);214 * assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(4.0);215 * assertThat(new double[] { 1.0, 2.0, 3.0 }).usingComparatorWithPrecision(0.05)216 * .containsOnlyOnce(1.1, 2.1);</code></pre>217 * 218 * @param values the given values.219 * @return {@code this} assertion object.220 * @throws NullPointerException if the given argument is {@code null}.221 * @throws IllegalArgumentException if the given argument is an empty array.222 * @throws AssertionError if the actual array is {@code null}.223 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group contains some224 * or none of the given values, or the actual group contains more than once these values.225 */226 public S containsOnlyOnce(double... values) {227 arrays.assertContainsOnlyOnce(info, actual, values);228 return myself;229 }230 /**231 * Verifies that the actual array contains the given values only once.232 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.233 * <p>234 * Examples :235 * <pre><code class='java'> // assertion will pass236 * assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(new double[] {1.1, 2.0}, withPrecision(0.2));237 *238 * // assertions will fail239 * assertThat(new double[] { 1.0, 2.0, 1.0 }).containsOnlyOnce(new double[] {1.05}, withPrecision(0.1));240 * assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(new double[] {4.0}, withPrecision(0.1));241 * assertThat(new double[] { 1.0, 2.0, 3.0, 3.0 }).containsOnlyOnce(new double[] {0.1, 0.9, 2.0, 3.11, 4.0, 5.0}, withPrecision(0.2));</code></pre>242 *243 * @param values the given values.244 * @param precision the precision under which the value may vary245 * @return {@code this} assertion object.246 * @throws NullPointerException if the given argument is {@code null}.247 * @throws IllegalArgumentException if the given argument is an empty array.248 * @throws AssertionError if the actual array is {@code null}.249 * @throws AssertionError if the actual group does not contain the given values, i.e. the actual group contains some250 * or none of the given values, or the actual group contains more than once these values.251 */252 public S containsOnlyOnce(double[] values, Offset<Double> precision) {253 usingComparatorWithPrecision(precision.value);254 return containsOnlyOnce(values);255 }256 /**257 * Verifies that the actual array contains the given sequence, without any other values between them.258 * <p>259 * If you want to set a precision for the comparison either use {@link #containsSequence(double[], Offset)} 260 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 261 * <p>262 * Examples :263 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };264 * 265 * // assertion will pass266 * assertThat(values).containsSequence(1.0, 2.0)267 * .containsSequence(1.0, 2.0, 3.0)268 * .containsSequence(2.0, 3.0)269 * .usingComparatorWithPrecision(0.5)270 * .containsSequence(1.1, 2.1);271 * 272 * // assertions will fail273 * assertThat(values).containsSequence(1.0, 3.0);274 * assertThat(values).containsSequence(4.0, 7.0);275 * assertThat(values).usingComparatorWithPrecision(0.01)276 * .containsSequence(1.1, 2.0, 3.0);</code></pre>277 * 278 * @param sequence the sequence of values to look for.279 * @return {@code this} assertion object.280 * @throws AssertionError if the actual array is {@code null}.281 * @throws AssertionError if the given array is {@code null}.282 * @throws AssertionError if the actual array does not contain the given sequence.283 */284 public S containsSequence(double... sequence) {285 arrays.assertContainsSequence(info, actual, sequence);286 return myself;287 }288 /**289 * Verifies that the actual array contains the given sequence, without any other values between them.290 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.291 * <p>292 * Examples :293 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };294 * 295 * // assertion will pass296 * assertThat(values).containsSequence(new double[] {1.07, 2.0}, withPrecision(0.1))297 * .containsSequence(new double[] {1.1, 2.1, 3.0}, withPrecision(0.2))298 * .containsSequence(new double[] {2.2, 3.0}, withPrecision(0.3));299 *300 * // assertions will fail301 * assertThat(values).containsSequence(new double[] {1.0, 3.0}, withPrecision(0.2));302 * assertThat(values).containsSequence(new double[] {4.0, 7.0}, withPrecision(0.1));</code></pre>303 *304 * @param sequence the sequence of values to look for.305 * @param precision the precision under which the value may vary306 * @return {@code this} assertion object.307 * @throws AssertionError if the actual array is {@code null}.308 * @throws AssertionError if the given array is {@code null}.309 * @throws AssertionError if the actual array does not contain the given sequence.310 */311 public S containsSequence(double[] sequence, Offset<Double> precision) {312 usingComparatorWithPrecision(precision.value);313 return containsSequence(sequence);314 }315 /**316 * Verifies that the actual array contains the given subsequence (possibly with other values between them).317 * <p>318 * If you want to set a precision for the comparison either use {@link #containsSubsequence(double[], Offset)} 319 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 320 * <p>321 * Examples :322 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };323 * 324 * // assertion will pass325 * assertThat(values).containsSubsequence(1.0, 2.0);326 * .containsSubsequence(1.0, 2.0, 3.0)327 * .containsSubsequence(1.0, 3.0)328 * .usingComparatorWithPrecision(0.5)329 * .containsSubsequence(1.1, 2.1);330 * 331 * // assertions will fail332 * assertThat(values).containsSubsequence(3.0, 1.0);333 * assertThat(values).containsSubsequence(4.0, 7.0);334 * assertThat(values).usingComparatorWithPrecision(0.01)335 * .containsSubsequence(1.1, 2.0);</code></pre>336 * 337 * @param subsequence the subsequence of values to look for.338 * @return {@code this} assertion object.339 * @throws AssertionError if the actual array is {@code null}.340 * @throws AssertionError if the given array is {@code null}.341 * @throws AssertionError if the actual array does not contain the given subsequence.342 */343 public S containsSubsequence(double... subsequence) {344 arrays.assertContainsSubsequence(info, actual, subsequence);345 return myself;346 }347 /**348 * Verifies that the actual array contains the given subsequence (possibly with other values between them).349 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.350 * <p>351 * Examples :352 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };353 * 354 * // assertion will pass355 * assertThat(values).containsSubsequence(new double[] {1.0, 2.0}, withPrecision(0.1))356 * .containsSubsequence(new double[] {1.0, 2.07, 3.0}, withPrecision(0.1))357 * .containsSubsequence(new double[] {2.1, 2.9}, withPrecision(0.2));358 *359 * // assertions will fail360 * assertThat(values).containsSubsequence(new double[] {1.0, 3.0}, withPrecision(0.1));361 * assertThat(values).containsSubsequence(new double[] {4.0, 7.0}, withPrecision(0.1));</code></pre>362 *363 * @param subsequence the subsequence of values to look for.364 * @param precision the precision under which the value may vary.365 * @return {@code this} assertion object.366 * @throws AssertionError if the actual array is {@code null}.367 * @throws AssertionError if the given array is {@code null}.368 * @throws AssertionError if the actual array does not contain the given subsequence.369 */370 public S containsSubsequence(double[] subsequence, Offset<Double> precision) {371 usingComparatorWithPrecision(precision.value);372 return containsSubsequence(subsequence);373 }374 /**375 * Verifies that the actual array contains the given value at the given index.376 * <p>377 * If you want to set a precision for the comparison either use {@link #contains(double, Index, Offset)} 378 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 379 * <p>380 * Example:381 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };382 * 383 * // assertion will pass384 * assertThat(values).contains(1.0, atIndex(O))385 * .contains(3.0, atIndex(2))386 * .usingComparatorWithPrecision(0.5)387 * .contains(3.1, atIndex(2));388 * 389 * // assertions will fail390 * assertThat(values).contains(1.0, atIndex(1));391 * assertThat(values).contains(4.0, atIndex(2));392 * assertThat(values).usingComparatorWithPrecision(0.01)393 * .contains(3.1, atIndex(2));</code></pre>394 * 395 * </p>396 * 397 * @param value the value to look for.398 * @param index the index where the value should be stored in the actual array.399 * @return {@code this} assertion object.400 * @throws AssertionError if the actual array is {@code null} or empty.401 * @throws NullPointerException if the given {@code Index} is {@code null}.402 * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of403 * the actual array.404 * @throws AssertionError if the actual array does not contain the given value at the given index.405 */406 public S contains(double value, Index index) {407 arrays.assertContains(info, actual, value, index);408 return myself;409 }410 /**411 * Verifies that the actual array contains the given value at the given index.412 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.413 * <p>414 * Example:415 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };416 * 417 * // assertion will pass418 * assertThat(values).contains(1.0, atIndex(O), withPrecision(0.01))419 * .contains(3.3, atIndex(2), withPrecision(0.5));420 *421 * // assertions will fail422 * assertThat(values).contains(1.0, atIndex(1), withPrecision(0.2));423 * assertThat(values).contains(4.5, atIndex(2), withPrecision(0.1));</code></pre>424 *425 * </p>426 *427 * @param value the value to look for.428 * @param index the index where the value should be stored in the actual array.429 * @param precision the precision under which the value may vary.430 * @return {@code this} assertion object.431 * @throws AssertionError if the actual array is {@code null} or empty.432 * @throws NullPointerException if the given {@code Index} is {@code null}.433 * @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of434 * the actual array.435 * @throws AssertionError if the actual array does not contain the given value at the given index.436 */437 public S contains(double value, Index index, Offset<Double> precision) {438 usingComparatorWithPrecision(precision.value);439 return contains(value, index);440 }441 /**442 * Verifies that the actual array does not contain the given values.443 * <p>444 * If you want to set a precision for the comparison either use {@link #doesNotContain(double[], Offset)} 445 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 446 * <p>447 * Example:448 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };449 * 450 * // assertion will pass451 * assertThat(values).doesNotContain(4.0, 8.0)452 * .usingComparatorWithPrecision(0.0001)453 * .doesNotContain(1.01, 2.01);454 * 455 * // assertions will fail456 * assertThat(values).doesNotContain(1.0, 4.0, 8.0);457 * assertThat(values).usingComparatorWithPrecision(0.1)458 * .doesNotContain(1.001, 2.001);</code></pre>459 * 460 * @param values the given values.461 * @return {@code this} assertion object.462 * @throws NullPointerException if the given argument is {@code null}.463 * @throws IllegalArgumentException if the given argument is an empty array.464 * @throws AssertionError if the actual array is {@code null}.465 * @throws AssertionError if the actual array contains any of the given values.466 */467 public S doesNotContain(double... values) {468 arrays.assertDoesNotContain(info, actual, values);469 return myself;470 }471 /**472 * Verifies that the actual array does not contain the given values.473 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.474 * <p>475 * Example:476 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };477 * 478 * // assertion will pass479 * assertThat(values).doesNotContain(new double[] {4.0, 8.0}, withPrecision(0.5));480 *481 * // assertion will fail482 * assertThat(values).doesNotContain(new double[] {1.05, 4.0, 8.0}, withPrecision(0.1));</code></pre>483 *484 * @param values the given values.485 * @param precision the precision under which the values may vary.486 * @return {@code this} assertion object.487 * @throws NullPointerException if the given argument is {@code null}.488 * @throws IllegalArgumentException if the given argument is an empty array.489 * @throws AssertionError if the actual array is {@code null}.490 * @throws AssertionError if the actual array contains any of the given values.491 */492 public S doesNotContain(double[] values, Offset<Double> precision) {493 usingComparatorWithPrecision(precision.value);494 arrays.assertDoesNotContain(info, actual, values);495 return myself;496 }497 /**498 * Verifies that the actual array does not contain the given value at the given index.499 * <p>500 * If you want to set a precision for the comparison either use {@link #doesNotContain(double, Index, Offset)} 501 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 502 * <p>503 * Example:504 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };505 * 506 * // assertion will pass507 * assertThat(values).doesNotContain(1.0, atIndex(1))508 * .doesNotContain(2.0, atIndex(0))509 * .usingComparatorWithPrecision(0.001)510 * .doesNotContain(1.1, atIndex(0));511 * 512 * // assertions will fail513 * assertThat(values).doesNotContain(1.0, atIndex(0));514 * assertThat(values).usingComparatorWithPrecision(0.1)515 * .doesNotContain(1.001, atIndex(0));</code></pre>516 * 517 * </p>518 * 519 * @param value the value to look for.520 * @param index the index where the value should be stored in the actual array.521 * @return {@code this} assertion object.522 * @throws AssertionError if the actual array is {@code null}.523 * @throws NullPointerException if the given {@code Index} is {@code null}.524 * @throws AssertionError if the actual array contains the given value at the given index.525 */526 public S doesNotContain(double value, Index index) {527 arrays.assertDoesNotContain(info, actual, value, index);528 return myself;529 }530 /**531 * Verifies that the actual array does not contain the given value at the given index.532 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.533 * <p>534 * Example:535 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };536 * 537 * // assertion will pass538 * assertThat(values).doesNotContain(1.01, atIndex(1), withPrecision(0.0001))539 * .doesNotContain(2.05, atIndex(0), withPrecision(0.1));540 *541 * // assertion will fail542 * assertThat(values).doesNotContain(1.01, atIndex(0), withPrecision(0.1));</code></pre>543 *544 * @param value the value to look for.545 * @param index the index where the value should be stored in the actual array.546 * @param precision the precision under which the values may vary.547 * @return {@code this} assertion object.548 * @throws AssertionError if the actual array is {@code null}.549 * @throws NullPointerException if the given {@code Index} is {@code null}.550 * @throws AssertionError if the actual array contains the given value at the given index.551 */552 public S doesNotContain(double value, Index index, Offset<Double> precision) {553 usingComparatorWithPrecision(precision.value);554 return doesNotContain(value, index);555 }556 /**557 * Verifies that the actual array does not contain duplicates.558 * <p>559 * If you want to set a precision for the comparison either use {@link #doesNotHaveDuplicates(Offset)} 560 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 561 * <p>562 * Example:563 * <pre><code class='java'> // assertion will pass564 * assertThat(new double[] { 1.0, 2.0, 3.0 }).doesNotHaveDuplicates();565 * assertThat(new double[] { 1.0, 1.1 }).usingComparatorWithPrecision(0.01)566 * .doesNotHaveDuplicates();567 * 568 * // assertion will fail569 * assertThat(new double[] { 1.0, 1.0, 2.0, 3.0 }).doesNotHaveDuplicates();570 * assertThat(new double[] { 1.0, 1.1 }).usingComparatorWithPrecision(0.5)571 * .doesNotHaveDuplicates();</code></pre>572 * 573 * @return {@code this} assertion object.574 * @throws AssertionError if the actual array is {@code null}.575 * @throws AssertionError if the actual array contains duplicates.576 */577 public S doesNotHaveDuplicates() {578 arrays.assertDoesNotHaveDuplicates(info, actual);579 return myself;580 }581 /**582 * Verifies that the actual array does not contain duplicates.583 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.584 * <p>585 * Example:586 * <pre><code class='java'> // assertion will pass587 * assertThat(new double[] { 1.0, 2.0, 3.0 }).doesNotHaveDuplicates(withPrecision(0.1));588 * assertThat(new double[] { 1.1, 1.2, 1.3 }).doesNotHaveDuplicates(withPrecision(0.05));589 * 590 * // assertion will fail591 * assertThat(new double[] { 1.0, 1.01, 2.0 }).doesNotHaveDuplicates(withPrecision(0.1));</code></pre>592 * 593 * </p>594 * 595 * @param precision the precision under which the values may vary.596 * @return {@code this} assertion object.597 * @throws AssertionError if the actual array is {@code null}.598 * @throws AssertionError if the actual array contains duplicates.599 */600 public S doesNotHaveDuplicates(Offset<Double> precision) {601 usingComparatorWithPrecision(precision.value);602 return doesNotHaveDuplicates();603 }604 605 /**606 * Verifies that the actual array starts with the given sequence of values, without any other values between them.607 * Similar to <code>{@link #containsSequence(double...)}</code>, but it also verifies that the first element in the608 * sequence is also first element of the actual array.609 * <p>610 * If you want to set a precision for the comparison either use {@link #startsWith(double[], Offset)} 611 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 612 * <p>613 * Example:614 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };615 * 616 * // assertion will pass617 * assertThat(values).startsWith(1.0, 2.0)618 * .usingComparatorWithPrecision(0.5)619 * .startsWith(1.1, 2.1);620 * 621 * // assertion will fail622 * assertThat(values).startsWith(2.0, 3.0);</code></pre>623 * 624 * </p>625 * 626 * @param sequence the sequence of values to look for.627 * @return {@code this} assertion object.628 * @throws NullPointerException if the given argument is {@code null}.629 * @throws IllegalArgumentException if the given argument is an empty array.630 * @throws AssertionError if the actual array is {@code null}.631 * @throws AssertionError if the actual array does not start with the given sequence.632 */633 public S startsWith(double... sequence) {634 arrays.assertStartsWith(info, actual, sequence);635 return myself;636 }637 /**638 * Verifies that the actual array starts with the given sequence of values, without any other values between them.639 * Similar to <code>{@link #containsSequence(double...)}</code>, but it also verifies that the first element in the640 * sequence is also first element of the actual array.641 * <p>642 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.643 * <p>644 * Example:645 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };646 * 647 * // assertion will pass648 * assertThat(values).startsWith(new double[] {1.01, 2.01}, withPrecision(0.1));649 * 650 * // assertions will fail651 * assertThat(values).startsWith(new double[] {2.0, 1.0}, withPrecision(0.1))652 * assertThat(values).startsWith(new double[] {1.1, 2.1}, withPrecision(0.5))</code></pre>653 * 654 * @param sequence the sequence of values to look for.655 * @param precision the precision under which the values may vary.656 * @return {@code this} assertion object.657 * @throws NullPointerException if the given argument is {@code null}.658 * @throws IllegalArgumentException if the given argument is an empty array.659 * @throws AssertionError if the actual array is {@code null}.660 * @throws AssertionError if the actual array does not end with the given sequence.661 */662 public S startsWith(double[] values, Offset<Double> precision) {663 usingComparatorWithPrecision(precision.value);664 return startsWith(values);665 }666 667 /**668 * Verifies that the actual array ends with the given sequence of values, without any other values between them.669 * Similar to <code>{@link #containsSequence(double...)}</code>, but it also verifies that the last element in the670 * sequence is also last element of the actual array.671 * <p>672 * If you want to set a precision for the comparison either use {@link #endsWith(double[], Offset)} 673 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 674 * <p>675 * Example:676 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };677 * 678 * // assertion will pass679 * assertThat(values).endsWith(2.0, 3.0)680 * .usingComparatorWithPrecision(0.5)681 * .endsWith(2.1, 3.1);682 * 683 * // assertion will fail684 * assertThat(values).endsWith(1.0, 3.0);</code></pre>685 * 686 * @param sequence the sequence of values to look for.687 * @return {@code this} assertion object.688 * @throws NullPointerException if the given argument is {@code null}.689 * @throws IllegalArgumentException if the given argument is an empty array.690 * @throws AssertionError if the actual array is {@code null}.691 * @throws AssertionError if the actual array does not end with the given sequence.692 */693 public S endsWith(double... sequence) {694 arrays.assertEndsWith(info, actual, sequence);695 return myself;696 }697 /**698 * Verifies that the actual array ends with the given sequence of values, without any other values between them.699 * Similar to <code>{@link #containsSequence(double...)}</code>, but it also verifies that the last element in the700 * sequence is also last element of the actual array.701 * <p>702 * The comparison is done at the given precision/offset set with {@link Assertions#withPrecision(Double)}.703 * <p>704 * Example:705 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };706 * 707 * // assertion will pass708 * assertThat(values).endsWith(new double[] {2.01, 3.01}, withPrecision(0.1));709 * 710 * // assertion will fail711 * assertThat(values).endsWith(new double[] {3.0, 2.0}, withPrecision(0.1))712 * assertThat(values).endsWith(new double[] {2.1, 3.1}, withPrecision(0.5))</code></pre>713 * 714 * @param sequence the sequence of values to look for.715 * @param precision the precision under which the values may vary.716 * @return {@code this} assertion object.717 * @throws NullPointerException if the given argument is {@code null}.718 * @throws IllegalArgumentException if the given argument is an empty array.719 * @throws AssertionError if the actual array is {@code null}.720 * @throws AssertionError if the actual array does not end with the given sequence.721 */722 public S endsWith(double[] values, Offset<Double> precision) {723 usingComparatorWithPrecision(precision.value);724 return endsWith(values);725 }726 /** {@inheritDoc} */727 @Override728 public S isSorted() {729 arrays.assertIsSorted(info, actual);730 return myself;731 }732 /** {@inheritDoc} */733 @Override734 public S isSortedAccordingTo(Comparator<? super Double> comparator) {735 arrays.assertIsSortedAccordingToComparator(info, actual, comparator);736 return myself;737 }738 /** {@inheritDoc} */739 @Override740 public S usingElementComparator(Comparator<? super Double> customComparator) {741 this.arrays = new DoubleArrays(new ComparatorBasedComparisonStrategy(customComparator));742 return myself;743 }744 /** {@inheritDoc} */745 @Override746 public S usingDefaultElementComparator() {747 this.arrays = DoubleArrays.instance();748 return myself;749 }750 /**751 * <p>752 * Verifies that the actual group contains only the given values and nothing else, <b>in order</b>.753 * <p>754 * If you want to set a precision for the comparison either use {@link #containsExactly(double[], Offset)} 755 * or {@link #usingComparatorWithPrecision(Double)} before calling the assertion. 756 * <p>757 * Example :758 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };759 * 760 * // assertion will pass761 * assertThat(values).containsExactly(1.0, 2.0, 3.0)762 * .usingComparatorWithPrecision(0.2)763 * .containsExactly(1.1, 2.1, 2.9);764 * 765 * // assertion will fail as actual and expected orders differ.766 * assertThat(values).containsExactly(2.0, 1.0, 3.0);</code></pre>767 * 768 * @param values the given values.769 * @return {@code this} assertion object.770 * @throws NullPointerException if the given argument is {@code null}.771 * @throws AssertionError if the actual group is {@code null}.772 * @throws AssertionError if the actual group does not contain the given values with same order, i.e. the actual group773 * contains some or none of the given values, or the actual group contains more values than the given ones774 * or values are the same but the order is not.775 */776 public S containsExactly(double... values) {777 arrays.assertContainsExactly(info, actual, values);778 return myself;779 }780 /**781 * Verifies that the actual group contains only the given values and nothing else, <b>in order</b>.782 * The values may vary with a specified precision.783 * <p>784 * Example :785 * <pre><code class='java'> double[] values = new double[] { 1.0, 2.0, 3.0 };786 * 787 * // assertion will pass788 * assertThat(values).containsExactly(new double[] {1.0, 1.98, 3.01}, withPrecision(0.05));789 *790 * // assertion fails because |1.0 -1.1| > 0.05 (precision).791 * assertThat(values).containsExactly(new double[] {1.1, 2.0, 3.01}, withPrecision(0.05));792 * 793 * // assertion will fail as actual and expected orders differ.794 * assertThat(values).containsExactly(new double[] {1.98, 1.0, 3.01}, withPrecision(0.05));</code></pre>795 *796 * @param values the given values.797 * @param precision the precision under which the values may vary.798 * @return {@code this} assertion object.799 * @throws NullPointerException if the given argument is {@code null}.800 * @throws AssertionError if the actual group is {@code null}.801 * @throws AssertionError if the actual group does not contain the given values within the specified precision 802 * with same order, i.e. the actual group contains some or none of the given values, or the actual group contains 803 * more values than the given ones or values are the same but the order is not.804 */805 public S containsExactly(double[] values, Offset<Double> precision) {806 usingComparatorWithPrecision(precision.value);807 return containsExactly(values);808 }809 /**810 * Create a {@link Double} comparator which compares double at the given precision and pass it to {@link #usingElementComparator(Comparator)}. 811 * All the following assertions will use this comparator to compare double[] elements.812 * 813 * @param precision precisin used to compare {@link Double}.814 * @return {@code this} assertion object.815 */816 public S usingComparatorWithPrecision(Double precision) {817 return usingElementComparator(doubleComparator.doubleComparatorWithPrecision(precision));818 }819}...

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1double[] actual = new double[] {1.0, 2.0, 3.0, 4.0, 5.0};2assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.1, 2.2, 3.3, 4.4, 5.5);3assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.0, 2.0, 3.0, 4.0, 5.0);4assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.1, 2.0, 3.0, 4.0, 5.0);5assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.0, 2.2, 3.0, 4.0, 5.0);6assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.0, 2.0, 3.3, 4.0, 5.0);7assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.0, 2.0, 3.0, 4.4, 5.0);8assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.0, 2.0, 3.0, 4.0, 5.5);9assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.1, 2.2, 3.3, 4.4, 5.5);10assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.0, 2.2, 3.3, 4.4, 5.5);11assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.1, 2.0, 3.3, 4.4, 5.5);12assertThat(actual).usingComparatorWithPrecision(0.1).contains(1.1, 2.2, 3.0, 4.4, 5.5);

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.api.Assertions.within;3import static org.assertj.core.api.Assertions.withinPercentage;4import static org.assertj.core.api.Assertions.withinPrecision;5double[] actual = { 1.0, 2.0, 3.0 };6double[] expected = { 1.01, 2.01, 3.01 };7assertThat(actual).usingComparatorWithPrecision(0.1).isEqualTo(expected);8assertThat(actual).usingComparatorWithPrecision(0.1).isEqualTo(expected);9assertThat(actual).usingComparatorWithPrecision(0.1).isCloseTo(expected, within(0.1));10assertThat(actual).usingComparatorWithPrecision(0.1).isCloseTo(expected, withinPercentage(5.0));11assertThat(actual).usingComparatorWithPrecision(0.1).isCloseTo(expected, withinPrecision(0.1));12assertThat(actual).usingComparatorWithPrecision(0.1).isEqualTo(expected);13assertThat(actual).usingComparatorWithPrecision(0.1).isCloseTo(expected, within(0.01));14assertThat(actual).usingComparatorWithPrecision(0.1).isCloseTo(expected, withinPercentage(0.5));15assertThat(actual).usingComparatorWithPrecision(0.1).isCloseTo(expected, withinPrecision(0.01));16assertThat(actual).usingComparatorWithPrecision(0.01).isEqualTo(expected);17assertThat(actual).usingComparatorWithPrecision(0.01).isCloseTo(expected, within(0.1));18assertThat(actual).usingComparatorWithPrecision(0.01).isCloseTo(expected, withinPercentage(5.0));19assertThat(actual).usingComparatorWithPrecision(0.01).isCloseTo(expected, withinPrecision(0.1));20assertThat(actual).usingComparatorWithPrecision(0.01).isEqualTo(expected);21assertThat(actual).usingComparatorWithPrecision(0.01).isCloseTo(expected, within(0.01));22assertThat(actual).usingComparatorWithPrecision(0.01).isCloseTo(expected, withinPercentage(0.5));23assertThat(actual).usingComparatorWithPrecision(0.01).isCloseTo(expected, withinPrecision(0.01));24assertThat(actual).usingComparatorWithPrecision(0.001).isEqualTo(expected);

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2public class AbstractDoubleArrayAssert_usingComparatorWithPrecision_Test {3 public static void main(String[] args) {4 double[] array = {1.0, 2.0, 3.0};5 Assertions.assertThat(array).usingComparatorWithPrecision(0.5).contains(1.5, 2.5);6 }7}8AssertJ DoubleArrayAssert containsExactlyInAnyOrder() Examples9AssertJ DoubleArrayAssert containsExactlyInAnyOrderElementsOf() Examples10AssertJ DoubleArrayAssert containsExactlyElementsOf() Examples11AssertJ DoubleArrayAssert containsExactly() Examples12AssertJ DoubleArrayAssert containsSequence() Examples13AssertJ DoubleArrayAssert containsSubsequence() Examples14AssertJ DoubleArrayAssert containsOnlyOnce() Examples15AssertJ DoubleArrayAssert containsOnlyOnceElementsOf() Examples16AssertJ DoubleArrayAssert containsOnlyOnceNull() Exa

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1double[] doubleArray = {1.0, 2.0, 3.0, 4.0, 5.0};2AbstractDoubleArrayAssert<?> doubleArrayAssert = assertThat(doubleArray);3doubleArrayAssert.usingComparatorWithPrecision(0.1);4Assertions.assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> doubleArrayAssert.usingComparatorWithPrecision(-0.1));5double[] doubleArray2 = {1.0, 2.0, 3.0, 4.0, 5.0};6AbstractDoubleArrayAssert<?> doubleArrayAssert2 = assertThat(doubleArray2);7Assertions.assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> doubleArrayAssert2.usingComparatorWithPrecision(-0.1));8Assertions.assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> doubleArrayAssert2.usingComparatorWithPrecision(0));9double[] doubleArray3 = {1.0, 2.0, 3.0, 4.0, 5.0};10AbstractDoubleArrayAssert<?> doubleArrayAssert3 = assertThat(doubleArray3);11Assertions.assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> doubleArrayAssert3.usingComparatorWithPrecision(-0.1));12Assertions.assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> doubleArrayAssert3.usingComparatorWithPrecision(0));13Assertions.assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> doubleArrayAssert3.usingComparatorWithPrecision(0.1));14double[] doubleArray4 = {1.0, 2.0, 3.0,

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2double[] doubleArray = {1.0, 2.0, 3.0};3assertThat(doubleArray).usingComparatorWithPrecision(0.1).contains(1.1, 2.1, 3.1);4import static org.assertj.core.api.Assertions.*;5double[] doubleArray = {1.0, 2.0, 3.0};6assertThat(doubleArray).usingComparatorWithPrecision(0.1).contains(1.1, 2.1, 3.1);7import static org.assertj.core.api.Assertions.*;8double[] doubleArray = {1.0, 2.0, 3.0};9assertThat(doubleArray).usingComparatorWithPrecision(0.1).contains(1.1, 2.1, 3.1);10import static org.assertj.core.api.Assertions.*;11double[] doubleArray = {1.0, 2.0, 3.0};12assertThat(doubleArray).usingComparatorWithPrecision(0.1).contains(1.1, 2.1, 3.1);13import static org.assertj.core.api.Assertions.*;14double[] doubleArray = {1.0, 2.0, 3.0};15assertThat(doubleArray).usingComparatorWithPrecision(0.1).contains(1.1, 2.1, 3.1);16import static org.assertj.core.api.Assertions.*;17double[] doubleArray = {1.0, 2.0, 3.0};18assertThat(doubleArray).usingComparatorWithPrecision(0.1).contains(1.1, 2.1,

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1import static java.lang.Math.abs;2import static org.assertj.core.api.Assertions.assertThat;3public class DoubleArrayAssert_usingComparatorWithPrecision_Test {4 public void test_usingComparatorWithPrecision_assertion() {5 double[] actual = { 1.0, 2.0, 3.0 };6 double[] expected = { 1.1, 2.1, 3.1 };7 assertThat(actual).usingComparatorWithPrecision(0.1).isEqualTo(expected);8 }9}10public void test_usingComparatorWithPrecision_assertion() {11 double[] actual = { 1.0, 2.0, 3.0 };12 float[] expected = { 1.1f, 2.1f, 3.1f };13 assertThat(actual).usingComparatorWithPrecision(0.1f).isEqualTo(expected);14}15public void test_usingComparatorWithPrecision_assertion() {16 double[] actual = { 1.0, 2.0, 3.0 };17 float[] expected = { 1.1f, 2.1f, 3.1f };

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.api.Assertions.within;3double[] doubleArray = {1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};4assertThat(doubleArray).usingComparatorWithPrecision(0.01).contains(2.2, 3.3, 4.4);5assertThat(doubleArray).usingComparatorWithPrecision(0.01).contains(2.2, 3.3, 4.4, 5.5);6assertThat(doubleArray).usingComparatorWithPrecision(0.01).contains(2.2, 3.3, 4.4, 5.5, 6.6);7assertThat(doubleArray).usingComparatorWithPrecision(0.01).contains(2.2, 3.3, 4.4, 5.5, 6.6, 7.7);8assertThat(doubleArray).usingComparatorWithPrecision(0.01).contains(2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8);9assertThat(doubleArray).usingComparatorWithPrecision(0.01).contains(2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9);

Full Screen

Full Screen

usingComparatorWithPrecision

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import static org.assertj.core.api.Assertions.within;3import static org.assertj.core.api.Assertions.withinPercentage;4double[] actual = {5.3, 6.2, 7.8, 8.4, 9.6};5assertThat(actual).usingComparatorWithPrecision(0.5).contains(5.5, 6.1, 7.9, 8.5, 9.5);6assertThat(actual).usingComparatorWithPrecision(0.5).contains(5.5, 6.1, 7.9, 8.5, 9.5);7import static org.assertj.core.api.Assertions.*;8import static org.assertj.core.api.Assertions.within;9import static org.assertj.core.api.Assertions.withinPercentage;10float[] actual = {5.3f, 6.2f, 7.8f, 8.4f, 9.6f};11assertThat(actual).usingComparatorWithPrecision(0.5f).contains(5.5f, 6.1f, 7.9f, 8.5f, 9.5f);12assertThat(actual).usingComparatorWithPrecision(0.5f).contains(5.5f, 6.1f, 7.9f, 8.5f, 9.5f);

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful