How to use noCustomComparatorSet method of org.assertj.core.api.AbstractFloatAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractFloatAssert.noCustomComparatorSet

Source:AbstractFloatAssert.java Github

copy

Full Screen

...174 * @throws AssertionError if the actual value is {@code null}.175 * @throws AssertionError if the actual value is not equal to the given one.176 */177 public SELF isEqualTo(float expected) {178 if (noCustomComparatorSet()) {179 // use primitive comparison since the parameter is a primitive.180 if (expected == actual.floatValue()) return myself;181 // at this point we know that the assertion failed, if actual and expected are Float.NaN first we want182 // to give a clear error message (we need to use equals to check that as Float.NaN != Float.NaN)183 if (Float.valueOf(expected).equals(Float.NaN) && actual.equals(Float.NaN))184 throw new AssertionError("Actual and expected values were compared with == because expected was a primitive float, the assertion failed as both were Float.NaN and Float.NaN != Float.NaN (as per Float#equals javadoc)");185 // standard error message186 throw Failures.instance().failure(info, shouldBeEqual(actual, expected, info.representation()));187 }188 floats.assertEqual(info, actual, expected);189 return myself;190 }191 /**192 * Verifies that the actual value is equal to the given one using {@link Float#equals(Object)} semantics where 0.0f is not equal to -0.0f.193 * <p>194 * Examples:195 * <pre><code class='java'> // assertion will pass:196 * assertThat(1.0f).isEqualTo(Float.valueOf(1.0f));197 *198 * // assertions will fail:199 * assertThat(0.0f).isEqualTo(Float.valueOf(1.0f));200 * assertThat(-1.0f).isEqualTo(Float.valueOf(1.0f));201 * assertThat(-0.0f).isEqualTo(Float.valueOf(0.0f));</code></pre>202 * <p>203 * Note that this assertion behaves slightly differently from {@link #isEqualTo(float)}.204 *205 * @param expected the given value to compare the actual value to.206 * @return {@code this} assertion object.207 * @throws AssertionError if the actual value is {@code null}.208 * @throws AssertionError if the actual value is not equal to the given one.209 */210 public SELF isEqualTo(Float expected) {211 // overloaded for javadoc212 return super.isEqualTo(expected);213 }214 /**215 * Verifies that the actual number is close to the given one within the given offset value.216 * <p>217 * When <i>abs(actual - expected) == offset value</i>, the assertion:218 * <ul>219 * <li><b>succeeds</b> when using {@link Assertions#within(Float)} or {@link Assertions#offset(Float)}</li>220 * <li><b>fails</b> when using {@link Assertions#byLessThan(Float)} or {@link Offset#strictOffset(Number)}</li>221 * </ul>222 * <p>223 * <b>Breaking change</b> since 2.9.0/3.9.0: using {@link Assertions#byLessThan(Float)} implies a <b>strict</b> comparison,224 * use {@link Assertions#within(Float)} to get the old behavior.225 * <p>226 * Examples:227 * <pre><code class='java'> // assertions succeed228 * assertThat(8.1f).isCloseTo(8.0f, within(0.2f));229 * assertThat(8.1f).isCloseTo(8.0f, offset(0.2f)); // alias of within230 * assertThat(8.1f).isCloseTo(8.0f, byLessThan(0.2f)); // strict231 *232 * // assertions succeed when the difference == offset value ...233 * assertThat(0.1f).isCloseTo(0.0f, within(0.1f));234 * assertThat(0.1f).isCloseTo(0.0f, offset(0.1f));235 * // ... except when using byLessThan which implies a strict comparison236 * assertThat(0.1f).isCloseTo(0.0f, byLessThan(0.1f)); // strict =&gt; fail237 *238 * // this assertion also fails239 * assertThat(8.1f).isCloseTo(8.0f, within(0.001f));</code></pre>240 *241 * @param expected the given number to compare the actual value to.242 * @param offset the given positive offset.243 * @return {@code this} assertion object.244 * @throws NullPointerException if the given offset is {@code null}.245 * @throws NullPointerException if the expected number is {@code null}.246 * @throws AssertionError if the actual value is not close to the given one.247 */248 // duplicate javadoc of isCloseTo(Float other, Offset<Float> offset but can't define it in super class249 public SELF isCloseTo(final float expected, final Offset<Float> offset) {250 floats.assertIsCloseTo(info, actual, expected, offset);251 return myself;252 }253 /**254 * Verifies that the actual number is not close to the given one by less than the given offset.<br>255 * <p>256 * When <i>abs(actual - expected) == offset value</i>, the assertion:257 * <ul>258 * <li><b>succeeds</b> when using {@link Assertions#byLessThan(Float)} or {@link Offset#strictOffset(Number)}</li>259 * <li><b>fails</b> when using {@link Assertions#within(Float)} or {@link Assertions#offset(Float)}</li>260 * </ul>261 * <p>262 * <b>Breaking change</b> since 2.9.0/3.9.0: using {@link Assertions#byLessThan(Float)} implies a <b>strict</b> comparison,263 * use {@link Assertions#within(Float)} to get the old behavior.264 * <p>265 * Examples:266 * <pre><code class='java'> // assertions succeed267 * assertThat(8.1f).isNotCloseTo(8.0f, byLessThan(0.01f));268 * assertThat(8.1f).isNotCloseTo(8.0f, within(0.01f));269 * assertThat(8.1f).isNotCloseTo(8.0f, offset(0.01f));270 * // diff == offset but isNotCloseTo succeeds as we use byLessThan271 * assertThat(0.1f).isNotCloseTo(0.0f, byLessThan(0.1f));272 *273 * // assertions fail274 * assertThat(0.1f).isNotCloseTo(0.0f, within(0.1f));275 * assertThat(0.1f).isNotCloseTo(0.0f, offset(0.1f));276 * assertThat(8.1f).isNotCloseTo(8.0f, within(0.2f));277 * assertThat(8.1f).isNotCloseTo(8.0f, offset(0.2f));278 * assertThat(8.1f).isNotCloseTo(8.0f, byLessThan(0.2f));</code></pre>279 *280 * @param expected the given number to compare the actual value to.281 * @param offset the given positive offset.282 * @return {@code this} assertion object.283 * @throws NullPointerException if the given offset is {@code null}.284 * @throws NullPointerException if the expected number is {@code null}.285 * @throws AssertionError if the actual value is close to the given one.286 * @see Assertions#byLessThan(Float)287 * @since 2.6.0 / 3.6.0288 */289 // duplicate javadoc of isNotCloseTo(Float other, Offset<Float> offset but can't define it in super class290 public SELF isNotCloseTo(final float expected, final Offset<Float> offset) {291 floats.assertIsNotCloseTo(info, actual, expected, offset);292 return myself;293 }294 /**295 * Verifies that the actual number is close to the given one within the given offset value.296 * <p>297 * When <i>abs(actual - expected) == offset value</i>, the assertion:298 * <ul>299 * <li><b>succeeds</b> when using {@link Assertions#within(Float)} or {@link Assertions#offset(Float)}</li>300 * <li><b>fails</b> when using {@link Assertions#byLessThan(Float)} or {@link Offset#strictOffset(Number)}</li>301 * </ul>302 * <p>303 * <b>Breaking change</b> since 2.9.0/3.9.0: using {@link Assertions#byLessThan(Float)} implies a <b>strict</b> comparison,304 * use {@link Assertions#within(Float)} to get the old behavior.305 * <p>306 * Examples:307 * <pre><code class='java'> // assertions succeed308 * assertThat(8.1f).isCloseTo(8.0f, within(0.2f));309 * assertThat(8.1f).isCloseTo(8.0f, offset(0.2f)); // alias of within310 * assertThat(8.1f).isCloseTo(8.0f, byLessThan(0.2f)); // strict311 *312 * // assertions succeed when the difference == offset value ...313 * assertThat(0.1f).isCloseTo(0.0f, within(0.1f));314 * assertThat(0.1f).isCloseTo(0.0f, offset(0.1f));315 * // ... except when using byLessThan which implies a strict comparison316 * assertThat(0.1f).isCloseTo(0.0f, byLessThan(0.1f)); // strict =&gt; fail317 *318 * // this assertion also fails319 * assertThat(8.1f).isCloseTo(8.0f, within(0.001f));</code></pre>320 *321 * @param expected the given number to compare the actual value to.322 * @param offset the given positive offset.323 * @return {@code this} assertion object.324 * @throws NullPointerException if the given offset is {@code null}.325 * @throws NullPointerException if the expected number is {@code null}.326 * @throws AssertionError if the actual value is not close to the given one.327 */328 @Override329 public SELF isCloseTo(Float expected, Offset<Float> offset) {330 floats.assertIsCloseTo(info, actual, expected, offset);331 return myself;332 }333 /**334 * Verifies that the actual number is not close to the given one by less than the given offset.<br>335 * <p>336 * When <i>abs(actual - expected) == offset value</i>, the assertion:337 * <ul>338 * <li><b>succeeds</b> when using {@link Assertions#byLessThan(Float)} or {@link Offset#strictOffset(Number)}</li>339 * <li><b>fails</b> when using {@link Assertions#within(Float)} or {@link Assertions#offset(Float)}</li>340 * </ul>341 * <p>342 * <b>Breaking change</b> since 2.9.0/3.9.0: using {@link Assertions#byLessThan(Float)} implies a <b>strict</b> comparison,343 * use {@link Assertions#within(Float)} to get the old behavior.344 * <p>345 * Examples:346 * <pre><code class='java'> // assertions succeed347 * assertThat(8.1f).isNotCloseTo(8.0f, byLessThan(0.01f));348 * assertThat(8.1f).isNotCloseTo(8.0f, within(0.01f));349 * assertThat(8.1f).isNotCloseTo(8.0f, offset(0.01f));350 * // diff == offset but isNotCloseTo succeeds as we use byLessThan351 * assertThat(0.1f).isNotCloseTo(0.0f, byLessThan(0.1f));352 *353 * // assertions fail354 * assertThat(0.1f).isNotCloseTo(0.0f, within(0.1f));355 * assertThat(0.1f).isNotCloseTo(0.0f, offset(0.1f));356 * assertThat(8.1f).isNotCloseTo(8.0f, within(0.2f));357 * assertThat(8.1f).isNotCloseTo(8.0f, offset(0.2f));358 * assertThat(8.1f).isNotCloseTo(8.0f, byLessThan(0.2f));</code></pre>359 *360 * @param expected the given number to compare the actual value to.361 * @param offset the given positive offset.362 * @return {@code this} assertion object.363 * @throws NullPointerException if the given offset is {@code null}.364 * @throws NullPointerException if the expected number is {@code null}.365 * @throws AssertionError if the actual value is close to the given one.366 * @see Assertions#byLessThan(Float)367 * @since 2.6.0 / 3.6.0368 */369 @Override370 public SELF isNotCloseTo(Float expected, Offset<Float> offset) {371 floats.assertIsNotCloseTo(info, actual, expected, offset);372 return myself;373 }374 /**375 * Verifies that the actual number is close to the given one within the given percentage.<br>376 * If difference is equal to the percentage value, assertion is considered valid.377 * <p>378 * Example with float:379 * <pre><code class='java'> // assertions will pass:380 * assertThat(11.0f).isCloseTo(new Float(10.0f), withinPercentage(20f));381 *382 * // if difference is exactly equals to the computed offset (1.0), it's ok383 * assertThat(11.0f).isCloseTo(new Float(10.0f), withinPercentage(10f));384 *385 * // assertion will fail386 * assertThat(11.0f).isCloseTo(new Float(10.0f), withinPercentage(5f));</code></pre>387 *388 * @param expected the given number to compare the actual value to.389 * @param percentage the given positive percentage.390 * @return {@code this} assertion object.391 * @throws NullPointerException if the given offset is {@code null}.392 * @throws NullPointerException if the expected number is {@code null}.393 * @throws AssertionError if the actual value is not close to the given one.394 */395 @Override396 public SELF isCloseTo(Float expected, Percentage percentage) {397 floats.assertIsCloseToPercentage(info, actual, expected, percentage);398 return myself;399 }400 /**401 * Verifies that the actual number is not close to the given one within the given percentage.<br>402 * If difference is equal to the percentage value, the assertion fails.403 * <p>404 * Example with float:405 * <pre><code class='java'> // assertion will pass:406 * assertThat(11.0f).isNotCloseTo(new Float(10.0f), withinPercentage(5f));407 *408 * // assertions will fail409 * assertThat(11.0f).isNotCloseTo(new Float(10.0f), withinPercentage(10f));410 * assertThat(11.0f).isNotCloseTo(new Float(10.0f), withinPercentage(20f));</code></pre>411 *412 * @param expected the given number to compare the actual value to.413 * @param percentage the given positive percentage.414 * @return {@code this} assertion object.415 * @throws NullPointerException if the given offset is {@code null}.416 * @throws NullPointerException if the expected number is {@code null}.417 * @throws AssertionError if the actual value is close to the given one.418 * @since 2.6.0 / 3.6.0419 */420 @Override421 public SELF isNotCloseTo(Float expected, Percentage percentage) {422 floats.assertIsNotCloseToPercentage(info, actual, expected, percentage);423 return myself;424 }425 /**426 * Verifies that the actual number is close to the given one within the given percentage.<br>427 * If difference is equal to the percentage value, assertion is considered valid.428 * <p>429 * Example with float:430 * <pre><code class='java'> // assertions will pass:431 * assertThat(11.0f).isCloseTo(10.0f, withinPercentage(20f));432 *433 * // if difference is exactly equals to the computed offset (1.0), it's ok434 * assertThat(11.0f).isCloseTo(10.0f, withinPercentage(10f));435 *436 * // assertion will fail437 * assertThat(11.0f).isCloseTo(10.0f, withinPercentage(5f));</code></pre>438 *439 * @param expected the given number to compare the actual value to.440 * @param percentage the given positive percentage.441 * @return {@code this} assertion object.442 * @throws NullPointerException if the given offset is {@code null}.443 * @throws NullPointerException if the expected number is {@code null}.444 * @throws AssertionError if the actual value is not close to the given one.445 */446 public SELF isCloseTo(float expected, Percentage percentage) {447 floats.assertIsCloseToPercentage(info, actual, expected, percentage);448 return myself;449 }450 /**451 * Verifies that the actual number is not close to the given one within the given percentage.<br>452 * If difference is equal to the percentage value, the assertion fails.453 * <p>454 * Example with float:455 * <pre><code class='java'> // assertion will pass:456 * assertThat(11.0f).isNotCloseTo(10.0f, withinPercentage(5f));457 *458 * // assertions will fail459 * assertThat(11.0f).isNotCloseTo(10.0f, withinPercentage(10f));460 * assertThat(11.0f).isNotCloseTo(10.0f, withinPercentage(20f));</code></pre>461 *462 * @param expected the given number to compare the actual value to.463 * @param percentage the given positive percentage.464 * @return {@code this} assertion object.465 * @throws NullPointerException if the given offset is {@code null}.466 * @throws NullPointerException if the expected number is {@code null}.467 * @throws AssertionError if the actual value is close to the given one.468 * @since 2.6.0 / 3.6.0469 */470 public SELF isNotCloseTo(float expected, Percentage percentage) {471 floats.assertIsNotCloseToPercentage(info, actual, expected, percentage);472 return myself;473 }474 /**475 * Verifies that the actual number is close to the given one within the given offset value.476 * <p>477 * This assertion is the same as {@link #isCloseTo(float, Offset)}.478 * <p>479 * When <i>abs(actual - expected) == offset value</i>, the assertion:480 * <ul>481 * <li><b>succeeds</b> when using {@link Assertions#within(Float)} or {@link Assertions#offset(Float)}</li>482 * <li><b>fails</b> when using {@link Assertions#byLessThan(Float)} or {@link Offset#strictOffset(Number)}</li>483 * </ul>484 * <p>485 * Examples:486 * <pre><code class='java'> // assertions will pass487 * assertThat(8.1f).isEqualTo(8.0f, within(0.2f));488 * assertThat(8.1f).isEqualTo(8.0f, offset(0.2f)); // alias of within489 * assertThat(8.1f).isEqualTo(8.0f, byLessThan(0.2f)); // strict490 *491 * // assertions succeed when the difference == offset value ...492 * assertThat(0.1f).isEqualTo(0.0f, within(0.1f));493 * assertThat(0.1f).isEqualTo(0.0f, offset(0.1f));494 * // ... except when using byLessThan which implies a strict comparison495 * assertThat(0.1f).isEqualTo(0.0f, byLessThan(0.1f)); // strict =&gt; fail496 *497 * // this assertion also fails498 * assertThat(0.1f).isEqualTo(0.0f, within(0.001f));</code></pre>499 *500 * @param expected the given value to compare the actual value to.501 * @param offset the given positive offset.502 * @return {@code this} assertion object.503 * @throws NullPointerException if the given offset is {@code null}.504 * @throws NullPointerException if the expected number is {@code null}.505 * @throws AssertionError if the actual value is not equal to the given one.506 */507 @Override508 public SELF isEqualTo(Float expected, Offset<Float> offset) {509 return isCloseTo(expected, offset);510 }511 /**512 * Verifies that the actual number is close to the given one within the given offset value.513 * <p>514 * This assertion is the same as {@link #isCloseTo(float, Offset)}.515 * <p>516 * When <i>abs(actual - expected) == offset value</i>, the assertion:517 * <ul>518 * <li><b>succeeds</b> when using {@link Assertions#within(Float)} or {@link Assertions#offset(Float)}</li>519 * <li><b>fails</b> when using {@link Assertions#byLessThan(Float)} or {@link Offset#strictOffset(Number)}</li>520 * </ul>521 * <p>522 * Examples:523 * <pre><code class='java'> // assertions will pass524 * assertThat(8.1f).isEqualTo(8.0f, within(0.2f));525 * assertThat(8.1f).isEqualTo(8.0f, offset(0.2f)); // alias of within526 * assertThat(8.1f).isEqualTo(8.0f, byLessThan(0.2f)); // strict527 *528 * // assertions succeed when the difference == offset value ...529 * assertThat(0.1f).isEqualTo(0.0f, within(0.1f));530 * assertThat(0.1f).isEqualTo(0.0f, offset(0.1f));531 * // ... except when using byLessThan which implies a strict comparison532 * assertThat(0.1f).isEqualTo(0.0f, byLessThan(0.1f)); // strict =&gt; fail533 *534 * // this assertion also fails535 * assertThat(0.1f).isEqualTo(0.0f, within(0.001f));</code></pre>536 *537 * @param expected the given value to compare the actual value to.538 * @param offset the given positive offset.539 * @return {@code this} assertion object.540 * @throws NullPointerException if the given offset is {@code null}.541 * @throws NullPointerException if the expected number is {@code null}.542 * @throws AssertionError if the actual value is not equal to the given one.543 */544 public SELF isEqualTo(float expected, Offset<Float> offset) {545 return isCloseTo(expected, offset);546 }547 /**548 * Verifies that the actual value is not equal to the given one.549 * <p>550 * Unless a specific comparator has been set (with {@link #usingComparator(Comparator) usingComparator}) the equality is performed551 * with {@code !=} which is slightly different from {@link Float#equals(Object)} - notably:552 * <ul>553 * <li>{@code Float.NaN != Float.NaN} but {@code Float.valueOf(Float.NaN).equals(Float.NaN) == true}</li>554 * <li>{@code 0.0f == -0.0f} but {@code Float.valueOf(0.0f).equals(-0.0f) == false}</li>555 * </ul>556 * <p>557 * Examples:558 * <pre><code class='java'> // assertions will pass:559 * assertThat(0.0f).isNotEqualTo(1.0f);560 * assertThat(-1.0f).isNotEqualTo(1.0f);561 * assertThat(Float.NaN).isNotEqualTo(Float.NaN);562 *563 * // assertions will fail:564 * assertThat(1.0f).isNotEqualTo(1.0f);565 * assertThat(1f).isNotEqualTo(1.0f);566 * assertThat(0.0f).isNotEqualTo(-0.0f);</code></pre>567 * <p>568 * Note that this assertion behaves slightly differently from {@link #isNotEqualTo(Float)}.569 *570 * @param other the given value to compare the actual value to.571 * @return {@code this} assertion object.572 * @throws AssertionError if the actual value is {@code null}.573 * @throws AssertionError if the actual value is equal to the given one.574 */575 public SELF isNotEqualTo(float other) {576 if (noCustomComparatorSet()) {577 // use primitive comparison since the parameter is a primitive.578 if (other != actual.doubleValue()) return myself;579 throw Failures.instance().failure(info, shouldNotBeEqual(actual, other));580 }581 floats.assertNotEqual(info, actual, other);582 return myself;583 }584 /**585 * Verifies that the actual value is not equal to the given {@link Float} using {@link Float#equals(Object)} semantics where586 * <ul>587 * <li>{@code Float.valueOf(Float.NaN).equals(Float.NaN) == true} but {@code Float.NaN != Float.NaN}</li>588 * <li>{@code Float.valueOf(0.0f).equals(-0.0f) == false} but {@code 0.0f == -0.0f}</li>589 * </ul>590 * <p>591 * Examples:592 * <pre><code class='java'> // assertions will pass:593 * assertThat(0.0f).isNotEqualTo(Float.valueOf(1.0));594 * assertThat(-1.0).isNotEqualTo(Float.valueOf(1.0));595 * assertThat(0.0f).isNotEqualTo(Float.valueOf(-0.0f));596 *597 * // assertions will fail:598 * assertThat(1.0).isNotEqualTo(Float.valueOf(1.0));599 * assertThat(0.0f).isNotEqualTo(Float.valueOf(0.0f));600 * assertThat(Float.NaN).isNotEqualTo(Float.valueOf(Float.NaN));</code></pre>601 * <p>602 * Note that this assertion behaves slightly differently from {@link #isNotEqualTo(float)}.603 *604 * @param other the given value to compare the actual value to.605 * @return {@code this} assertion object.606 * @throws AssertionError if the actual value is {@code null}.607 * @throws AssertionError if the actual value is equal to the given one.608 */609 public SELF isNotEqualTo(Float other) {610 // overloaded for javadoc611 return super.isNotEqualTo(other);612 }613 /**614 * Verifies that the actual value is less than the given one.615 * <p>616 * Examples:617 * <pre><code class='java'> // assertions will pass:618 * assertThat(1.0f).isLessThan(2.0f);619 * assertThat(1.0f).isLessThan(1.01f);620 *621 * // assertions will fail:622 * assertThat(2.0f).isLessThan(1.0f);623 * assertThat(1.0f).isLessThan(1.0f);</code></pre>624 *625 * @param other the given value to compare the actual value to.626 * @return {@code this} assertion object.627 * @throws AssertionError if the actual value is {@code null}.628 * @throws AssertionError if the actual value is equal to or greater than the given one.629 */630 public SELF isLessThan(float other) {631 floats.assertLessThan(info, actual, other);632 return myself;633 }634 /**635 * Verifies that the actual value is less than or equal to the given one.636 * <p>637 * Unless a specific comparator has been set (with {@link #usingComparator(Comparator) usingComparator})638 * this assertion will use {@code <=} semantics where notably {@code 0.0} == {@code -0.0}.639 * <p>640 * Examples:641 * <pre><code class='java'> // assertions will pass:642 * assertThat(-1.0f).isLessThanOrEqualTo(1.0f);643 * assertThat(1.0f).isLessThanOrEqualTo(1.0f);644 * // 0.0f == -0.0f645 * assertThat(-0.0f).isLessThanOrEqualTo(0.0f);646 * assertThat(0.0f).isLessThanOrEqualTo(-0.0f);647 *648 * // assertion will fail:649 * assertThat(2.0f).isLessThanOrEqualTo(1.0f);</code></pre>650 * <p>651 * Note that this assertion behaves differently from {@link #isLessThanOrEqualTo(Float)} which uses {@link Float#compareTo(Float)} semantics.652 *653 * @param other the given value to compare the actual value to.654 * @return {@code this} assertion object.655 * @throws AssertionError if the actual value is {@code null}.656 * @throws AssertionError if the actual value is greater than the given one.657 */658 public SELF isLessThanOrEqualTo(float other) {659 if (noCustomComparatorSet()) {660 // use primitive comparison since the parameter is a primitive.661 if (actual.floatValue() <= other) return myself;662 throw Failures.instance().failure(info, shouldBeLessOrEqual(actual, other));663 }664 floats.assertLessThanOrEqualTo(info, actual, other);665 return myself;666 }667 /**668 * Verifies that the actual value is less than or equal to the given one using {@link Float#compareTo(Float)} semantics where notably {@code -0.0} is <b>strictly</b> less than {@code 0.0}.669 * <p>670 * Examples:671 * <pre><code class='java'> // assertions will pass:672 * assertThat(-1.0f).isLessThanOrEqualTo(Float.valueOf(1.0f));673 * assertThat(1.0f).isLessThanOrEqualTo(Float.valueOf(1.0f));674 * assertThat(-0.0f).isLessThanOrEqualTo(Float.valueOf(0.0f));675 *676 * // assertions will fail:677 * assertThat(2.0f).isLessThanOrEqualTo(Float.valueOf(1.0f));678 * // 0.0f is not considered equal to -0.0f679 * assertThat(0.0f).isLessThanOrEqualTo(Float.valueOf(-0.0f));</code></pre>680 * <p>681 * Note that this assertion behaves differently from {@link #isLessThanOrEqualTo(float)} which uses {@link Float#compareTo(Float)} semantics.682 *683 * @param other the given value to compare the actual value to.684 * @return {@code this} assertion object.685 * @throws AssertionError if the actual value is {@code null}.686 * @throws AssertionError if the actual value is greater than the given one.687 */688 @Override689 public SELF isLessThanOrEqualTo(Float other) {690 // overridden for javadoc691 return super.isLessThanOrEqualTo(other);692 }693 /**694 * Verifies that the actual value is greater than the given one.695 * <p>696 * Examples:697 * <pre><code class='java'> // assertions will pass:698 * assertThat(2.0f).isGreaterThan(1.0f);699 * assertThat(2.0f).isGreaterThan(1.99f);700 *701 * // assertions will fail:702 * assertThat(1.0f).isGreaterThan(1.0f);703 * assertThat(1.0f).isGreaterThan(2.0f);</code></pre>704 *705 * @param other the given value to compare the actual value to.706 * @return {@code this} assertion object.707 * @throws AssertionError if the actual value is {@code null}.708 * @throws AssertionError if the actual value is equal to or less than the given one.709 */710 public SELF isGreaterThan(float other) {711 floats.assertGreaterThan(info, actual, other);712 return myself;713 }714 /**715 * Verifies that the actual value is greater than or equal to the given one.716 * <p>717 * Unless a specific comparator has been set (with {@link #usingComparator(Comparator) usingComparator})718 * this assertion will use {@code >=} semantics where notably {@code 0.0f} == {@code -0.0f}.719 * <p>720 * Examples:721 * <pre><code class='java'> // assertions will pass:722 * assertThat(2.0f).isGreaterThanOrEqualTo(1.0f);723 * assertThat(1.0f).isGreaterThanOrEqualTo(1.0f);724 * assertThat(0.0f).isGreaterThanOrEqualTo(-0.0f);725 *726 * // assertion will fail:727 * assertThat(1.0f).isGreaterThanOrEqualTo(2.0f);</code></pre>728 * <p>729 * Note that this assertion behaves differently from {@link #isGreaterThanOrEqualTo(Float)} which uses {@link Float#compareTo(Float)} semantics.730 *731 * @param other the given value to compare the actual value to.732 * @return {@code this} assertion object.733 * @throws AssertionError if the actual value is {@code null}.734 * @throws AssertionError if the actual value is less than the given one.735 */736 public SELF isGreaterThanOrEqualTo(float other) {737 if (noCustomComparatorSet()) {738 // use primitive comparison since the parameter is a primitive.739 if (actual.floatValue() >= other) return myself;740 throw Failures.instance().failure(info, shouldBeGreaterOrEqual(actual, other));741 }742 floats.assertGreaterThanOrEqualTo(info, actual, other);743 return myself;744 }745 /**746 * Verifies that the actual value is greater than or equal to the given one using {@link Float#compareTo(Float)} semantics where notably {@code 0.0f} is <b>strictly</b> greater than {@code -0.0f}.747 * <p>748 * Examples:749 * <pre><code class='java'> // assertions will pass:750 * assertThat(2.0f).isGreaterThanOrEqualTo(Float.valueOf(1.0f));751 * assertThat(1.0f).isGreaterThanOrEqualTo(Float.valueOf(1.0f));752 * assertThat(0.0f).isGreaterThanOrEqualTo(Float.valueOf(-0.0f));753 *754 * // assertions will fail:755 * assertThat(1.0f).isGreaterThanOrEqualTo(Float.valueOf(2.0f));756 * // 0.0f is not considered equal to -0.0f757 * assertThat(-0.0f).isGreaterThanOrEqualTo(Float.valueOf(0.0f));</code></pre>758 * <p>759 * Note that this assertion behaves differently from {@link #isGreaterThanOrEqualTo(float)} which uses {@code >=} semantics.760 *761 * @param other the given value to compare the actual value to.762 * @return {@code this} assertion object.763 * @throws AssertionError if the actual value is {@code null}.764 * @throws AssertionError if the actual value is less than the given one.765 */766 @Override767 public SELF isGreaterThanOrEqualTo(Float other) {768 // overridden for javadoc769 return super.isGreaterThanOrEqualTo(other);770 }771 /**772 * Verifies that the actual value is in [start, end] range (start included, end included).773 *774 * <p>775 * Examples:776 * <pre><code class='java'> // assertions will pass777 * assertThat(1f).isBetween(-1f, 2f);778 * assertThat(1f).isBetween(1f, 2f);779 * assertThat(1f).isBetween(0f, 1f);780 *781 * // assertion will fail782 * assertThat(1f).isBetween(2f, 3f);</code></pre>783 */784 @Override785 public SELF isBetween(Float start, Float end) {786 floats.assertIsBetween(info, actual, start, end);787 return myself;788 }789 /**790 * Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).791 *792 * <p>793 * Examples:794 * <pre><code class='java'> // assertion will pass795 * assertThat(1f).isStrictlyBetween(-1f, 2f);796 *797 * // assertions will fail798 * assertThat(1f).isStrictlyBetween(1f, 2f);799 * assertThat(1f).isStrictlyBetween(0f, 1f);800 * assertThat(1f).isStrictlyBetween(2f, 3f);</code></pre>801 *802 */803 @Override804 public SELF isStrictlyBetween(Float start, Float end) {805 floats.assertIsStrictlyBetween(info, actual, start, end);806 return myself;807 }808 @Override809 @CheckReturnValue810 public SELF usingComparator(Comparator<? super Float> customComparator) {811 return usingComparator(customComparator, null);812 }813 @Override814 @CheckReturnValue815 public SELF usingComparator(Comparator<? super Float> customComparator, String customComparatorDescription) {816 floats = new Floats(new ComparatorBasedComparisonStrategy(customComparator, customComparatorDescription));817 return super.usingComparator(customComparator, customComparatorDescription);818 }819 @Override820 @CheckReturnValue821 public SELF usingDefaultComparator() {822 floats = Floats.instance();823 return super.usingDefaultComparator();824 }825 private boolean noCustomComparatorSet() {826 return floats.getComparator() == null;827 }828}...

Full Screen

Full Screen

noCustomComparatorSet

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.junit.jupiter.api.Test;3public class AbstractFloatAssert_noCustomComparatorSet_Test {4 public void test_noCustomComparatorSet() {5 Assertions.assertThat(1.0f).noCustomComparatorSet();6 }7}8package org.assertj.core.api;9import static org.assertj.core.api.Assertions.assertThat;10import static org.assertj.core.util.FailureMessages.actualIsNull;11import org.assertj.core.internal.Floats;12import org.assertj.core.internal.Objects;13import org.assertj.core.util.VisibleForTesting;

Full Screen

Full Screen

noCustomComparatorSet

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AbstractFloatAssert;2public class AbstractFloatAssert_noCustomComparatorSet_Test {3 public static void main(String[] args) {4 AbstractFloatAssert<?> assertions = new ConcreteFloatAssert(0.0f);5 }6 private static class ConcreteFloatAssert extends AbstractFloatAssert<ConcreteFloatAssert> {7 public ConcreteFloatAssert(float actual) {8 super(actual, ConcreteFloatAssert.class);9 }10 }11}12org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED13org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() FAILED14org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED15org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() FAILED16org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED17org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() FAILED18org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED19org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() FAILED20org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED21org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() FAILED22org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED23org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() FAILED24org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED25org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() FAILED26org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test > main() PASSED

Full Screen

Full Screen

noCustomComparatorSet

Using AI Code Generation

copy

Full Screen

1 public void noCustomComparatorSet() {2 assertThat(1.0f).noCustomComparatorSet();3 }4 public void usingComparator() {5 assertThat(1.0f).usingComparator(new FloatComparator());6 }7 public void usingDefaultComparator() {8 assertThat(1.0f).usingDefaultComparator();9 }10 public void usingElementComparator() {11 assertThat(1.0f).usingElementComparator(new FloatComparator());12 }13 public void usingElementComparatorOnFields() {14 assertThat(1.0f).usingElementComparatorOnFields("field1", "field2");15 }16 public void usingRecursiveComparison() {17 assertThat(1.0f).usingRecursiveComparison();18 }19 public void usingTolerantComparison() {20 assertThat(1.0f).usingTolerantComparison(1.0f);21 }22 public void usingTolerantComparison1() {23 assertThat(1.0f).usingTolerantComparison(1.0f, 0.0f);24 }25 public void usingComparatorForFields() {26 assertThat(1.0f).usingComparatorForFields(new FloatComparator(), "field1", "field2");27 }28 public void usingComparatorForFields1() {29 assertThat(1.0f).usingComparatorForFields(new FloatComparator(), new String[]{"field1", "field2"});30 }31 public void usingComparatorForFields2()

Full Screen

Full Screen

noCustomComparatorSet

Using AI Code Generation

copy

Full Screen

1public class NoCustomComparatorSetTest {2 public void testNoCustomComparatorSet() {3 assertThat(1.0f).usingComparator(new Comparator<Float>() {4 public int compare(Float o1, Float o2) {5 return 0;6 }7 }).isCloseTo(2.0f, within(1.0f));8 assertThat(1.0f).noCustomComparatorSet().isCloseTo(2.0f, within(1.0f));9 }10}11at org.junit.Assert.assertEquals(Assert.java:115)12at org.junit.Assert.assertEquals(Assert.java:144)13at org.assertj.core.api.AbstractFloatAssert.isCloseTo(AbstractFloatAssert.java:79)14at org.assertj.core.api.AbstractFloatAssert.isCloseTo(AbstractFloatAssert.java:36)15at NoCustomComparatorSetTest.testNoCustomComparatorSet(NoCustomComparatorSetTest.java:16)

Full Screen

Full Screen

noCustomComparatorSet

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2public class AbstractFloatAssert_noCustomComparatorSet_Test {3 public void should_pass_if_actual_is_equal_to_other() {4 float actual = 42.0f;5 assertThat(actual).noCustomComparatorSet();6 }7 public void should_fail_if_actual_is_not_equal_to_other() {8 float actual = 42.0f;9 AssertionError assertionError = expectAssertionError(() -> assertThat(actual).noCustomComparatorSet());10 then(assertionError).hasMessage(shouldNotHaveCustomComparator(actual).create());11 }12 public void should_fail_if_actual_is_not_equal_to_other_by_comparing_using_given_comparator() {13 float actual = 42.0f;14 AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingComparator((f1, f2) -> 0).noCustomComparatorSet());15 then(assertionError).hasMessage(shouldNotHaveCustomComparator(actual).create());16 }17}

Full Screen

Full Screen

noCustomComparatorSet

Using AI Code Generation

copy

Full Screen

1public void testNoCustomComparatorSet() {2 assertThat(1.0f).noCustomComparatorSet();3}4public void testNoCustomComparatorSet() {5 assertThat(1.0f).noCustomComparatorSet();6}7public void testUsingComparator() {8 assertThat(1.0f).usingComparator(comparator);9}10public void testUsingDefaultComparator() {11 assertThat(1.0f).usingDefaultComparator();12}13public void testUsingFieldByFieldElementComparator() {14 assertThat(1.0f).usingFieldByFieldElementComparator();15}16public void testUsingRecursiveComparison() {17 assertThat(1.0f).usingRecursiveComparison();18}19public void testUsingElementComparator() {20 assertThat(1.0f).usingElementComparator(comparator);21}22public void testUsingComparatorForFields() {23 assertThat(1.0f).usingComparatorForFields(comparator, fields);24}25public void testUsingComparatorForType() {26 assertThat(1.0f).usingComparatorForType(comparator, type);27}28public void testUsingComparatorForFields() {29 assertThat(1.0f).usingComparatorForFields(comparator, fields);30}31public void testUsingComparatorForFields() {32 assertThat(1.0f).usingComparatorForFields(comparator, fields);33}

Full Screen

Full Screen

noCustomComparatorSet

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AbstractFloatAssert;2import org.junit.Test;3import static org.assertj.core.api.Assertions.assertThat;4import static org.assertj.core.api.Assertions.within;5public class AbstractFloatAssert_noCustomComparatorSet_Test {6 public void testNoCustomComparatorSet() {7 Float actual = 0.0f;8 AbstractFloatAssert<?> assertions = assertThat(actual);9 assertions.noCustomComparatorSet();10 }11}12at org.junit.Assert.assertEquals(Assert.java:115)13at org.junit.Assert.assertEquals(Assert.java:144)14at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:64)15at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:24)16at org.assertj.core.api.AbstractFloatAssert.noCustomComparatorSet(AbstractFloatAssert.java:218)17at org.assertj.core.api.AbstractFloatAssert_noCustomComparatorSet_Test.testNoCustomComparatorSet(AbstractFloatAssert_noCustomComparatorSet_Test.java:31)

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