How to use RealNumbers class of org.assertj.core.internal package

Best Assertj code snippet using org.assertj.core.internal.RealNumbers

Source:Doubles.java Github

copy

Full Screen

...23 * 24 * @author Alex Ruiz25 * @author Joel Costigliola26 */27public class Doubles extends RealNumbers<Double> {28 private static final Doubles INSTANCE = new Doubles();29 /**30 * Returns the singleton instance of this class based on {@link StandardComparisonStrategy}.31 * 32 * @return the singleton instance of this class based on {@link StandardComparisonStrategy}.33 */34 public static Doubles instance() {35 return INSTANCE;36 }37 @VisibleForTesting38 Doubles() {39 super();40 }41 public Doubles(ComparisonStrategy comparisonStrategy) {42 super(comparisonStrategy);43 }44 @Override45 protected Double zero() {46 return 0.0d;47 }48 @Override49 protected Double NaN() {50 return Double.NaN;51 }52 /**53 * Verifies that two floats are equal within a positive offset.<br>54 * It does not rely on the custom comparisonStrategy (if one is set) because using an offset is already a specific55 * comparison56 * strategy.57 * 58 * @param info contains information about the assertion.59 * @param actual the actual value.60 * @param expected the expected value.61 * @param offset the given positive offset.62 * @throws NullPointerException if the given offset is {@code null}.63 * @throws AssertionError if the actual value is {@code null}.64 * @throws AssertionError if the actual value is not equal to the expected one.65 */66 // can't be defined in RealNumbers because Offset parameter must inherits from Number67 // while RealNumber parameter must inherits from Comparable (sadly Number is not Comparable)68 public void assertEqual(AssertionInfo info, Double actual, Double expected, Offset<Double> offset) {69 checkOffsetIsNotNull(offset);70 checkNumberIsNotNull(expected);71 assertNotNull(info, actual);72 // doesn't use areEqual method relying on comparisonStrategy attribute73 if (Objects.areEqual(actual, expected)) return;74 if (isEqualTo(actual, expected, offset)) return;75 throw failures.failure(info, shouldBeEqual(actual, expected, offset, absDiff(actual, expected)));76 }77 @Override78 protected boolean isEqualTo(Double actual, Double expected, Offset<?> offset) {79 return absDiff(actual, expected) <= offset.value.doubleValue();80 }...

Full Screen

Full Screen

Source:Floats.java Github

copy

Full Screen

...25 * @author Alex Ruiz26 * @author Joel Costigliola27 * @author Mikhail Mazursky28 */29public class Floats extends RealNumbers<Float> {30 private static final Floats INSTANCE = new Floats();31 /**32 * Returns the singleton instance of this class based on {@link StandardComparisonStrategy}.33 * 34 * @return the singleton instance of this class based on {@link StandardComparisonStrategy}.35 */36 public static Floats instance() {37 return INSTANCE;38 }39 @VisibleForTesting40 Floats() {41 super();42 }43 public Floats(ComparisonStrategy comparisonStrategy) {44 super(comparisonStrategy);45 }46 @Override47 protected Float zero() {48 return 0.0f;49 }50 @Override51 protected Float NaN() {52 return Float.NaN;53 }54 @Override55 protected boolean isEqualTo(Float actual, Float expected, Offset<?> offset) {56 return abs(expected - actual) <= offset.value.floatValue();57 }58 @Override59 public void assertIsCloseTo(final AssertionInfo info, final Float actual, final Float expected,60 final Offset<Float> offset) {61 assertEqual(info, actual, expected, offset);62 }63 /**64 * Verifies that two floats are equal within a positive offset.<br>65 * It does not rely on the custom comparisonStrategy (if one is set) because using an offset is already a specific66 * comparison67 * strategy.68 * 69 * @param info contains information about the assertion.70 * @param actual the actual value.71 * @param expected the expected value.72 * @param offset the given positive offset.73 * @throws NullPointerException if the given offset is {@code null}.74 * @throws AssertionError if the actual value is not equal to the expected one.75 */76 // can't be defined in RealNumbers because Offset parameter must inherits from Number77 // while RealNumber parameter must inherits from Comparable (sadly Number is not Comparable)78 public void assertEqual(AssertionInfo info, Float actual, Float expected, Offset<Float> offset) {79 assertNotNull(info, actual);80 checkOffsetIsNotNull(offset);81 checkNumberIsNotNull(expected);82 // doesn't use areEqual method relying on comparisonStrategy attribute83 if (Objects.areEqual(actual, expected)) return;84 if (isEqualTo(actual, expected, offset)) return;85 throw failures.failure(info, shouldBeEqual(actual, expected, offset, abs(expected - actual)));86 }87}...

Full Screen

Full Screen

Source:RealNumbers.java Github

copy

Full Screen

...17 * Base class of reusable assertions for real numbers (float and double).18 * 19 * @author Joel Costigliola20 */21public abstract class RealNumbers<NUMBER extends Number & Comparable<NUMBER>> extends Numbers<NUMBER> {22 public RealNumbers() {23 super();24 }25 public RealNumbers(ComparisonStrategy comparisonStrategy) {26 super(comparisonStrategy);27 }28 /**29 * Verifies that the actual value is equal to {@code NaN}.<br>30 * It does not rely on the custom comparisonStrategy (if one is set).31 * 32 * @param info contains information about the assertion.33 * @param actual the actual value.34 * @throws AssertionError if the actual value is not equal to {@code NaN}.35 */36 public void assertIsNaN(AssertionInfo info, NUMBER actual) {37 assertEqualByComparison(info, actual, NaN());38 }39 protected abstract NUMBER NaN();...

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.internal;2import org.assertj.core.api.Assertions;3import org.assertj.core.data.Offset;4import org.assertj.core.data.Percentage;5import org.assertj.core.error.ShouldBeEqualWithinOffset;6import org.assertj.core.error.ShouldBeEqualWithinPercentage;7import org.assertj.core.error.ShouldHaveValue;8public class RealNumbers {9 public static void assertEqualByComparison(RealNumberAssert<?, ? extends Number> assertInstance, Number actual, Number expected) {10 if (actual instanceof Double || actual instanceof Float || expected instanceof Double || expected instanceof Float) {11 assertEqualByComparison(assertInstance, actual.doubleValue(), expected.doubleValue());12 } else {13 assertEqualByComparison(assertInstance, actual.longValue(), expected.longValue());14 }15 }16 public static void assertEqualByComparison(RealNumberAssert<?, ? extends Number> assertInstance, double actual, double expected) {17 if (actual != expected) {18 throw new AssertionError(ShouldBeEqualWithinOffset.shouldBeEqual(actual, expected, Offset.offset(0.0)).create());19 }20 }21 public static void assertEqualByComparison(RealNumberAssert<?, ? extends Number> assertInstance, long actual, long expected) {22 if (actual != expected) {23 throw new AssertionError(ShouldBeEqualWithinOffset.shouldBeEqual(actual, expected, Offset.offset(0.0)).create());24 }25 }26 public static void assertEqualByComparison(RealNumberAssert<?, ? extends Number> assertInstance, Number actual, Number expected, Offset<?> offset) {27 if (actual instanceof Double || actual instanceof Float || expected instanceof Double || expected instanceof Float) {28 assertEqualByComparison(assertInstance, actual.doubleValue(), expected.doubleValue(), offset);29 } else {30 assertEqualByComparison(assertInstance, actual.longValue(), expected.longValue(), offset);31 }32 }33 public static void assertEqualByComparison(RealNumberAssert<?, ? extends Number> assertInstance, double actual, double expected, Offset<?> offset) {34 if (!offset.valueIsInRange(actual, expected)) {35 throw new AssertionError(ShouldBeEqualWithinOffset.shouldBeEqual(actual, expected, offset).create());36 }37 }38 public static void assertEqualByComparison(RealNumberAssert<?, ? extends Number> assertInstance, long actual, long expected, Offset<?> offset) {39 if (!offset.valueIsInRange(actual, expected)) {40 throw new AssertionError(ShouldBeEqualWithinOffset.shouldBeEqual

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.RealNumbers;2import org.junit.Test;3import static org.assertj.core.api.Assertions.assertThat;4public class RealNumbersTest {5 private RealNumbers realNumbers = new RealNumbers();6 public void testAssertEqualByComparingFieldByField() {7 assertThat(1.0).isCloseTo(1.0, withinPercentage(0.0));8 }9}

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.internal;2import org.assertj.core.api.Assertions;3import org.junit.Test;4public class RealNumbersTest {5 public void test() {6 RealNumbers realNumbers = new RealNumbers();7 Assertions.assertThat(realNumbers).isNotNull();8 }9}

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import org.assertj.core.internal.RealNumbers;3import org.junit.Test;4public class RealNumbersTest {5 public void testAssertThat() {6 RealNumbers realNumbers = new RealNumbers();7 assertThat(realNumbers).isNotNull();8 assertThat(realNumbers.isEqual(1.0f, 1.0f)).isTrue();9 assertThat(realNumbers.isEqual(1.0f, 1.0f, 1.0f)).isTrue();10 assertThat(realNumbers.isEqual(1.0f, 1.0f, 1.0f, 1.0f)).isTrue();11 assertThat(realNumbers.isEqual

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.RealNumbers;2import org.assertj.core.internal.Failures;3import org.assertj.core.util.VisibleForTesting;4public class RealNumbersTest {5 Failures failures = Failures.instance();6 RealNumbers realNumbers = new RealNumbers();7 public void testAssertIsCloseTo() {8 realNumbers.assertIsCloseTo(failures, 1.0, 1.1, within(0.1));9 }10}11import org.assertj.core.internal.Failures;12import org.assertj.core.util.VisibleForTesting;13public class FailuresTest {14 Failures failures = Failures.instance();15 public void testFailure() {16 failures.failure("Some error message");17 }18}19import org.assertj.core.internal.Failures;20import org.assertj.core.util.VisibleForTesting;21public class FailuresTest {22 Failures failures = Failures.instance();23 public void testFailure() {24 failures.failure("Some error message");25 }26}27import org.assertj.core.internal.Failures;28import org.assertj.core.util.VisibleForTesting;29public class FailuresTest {30 Failures failures = Failures.instance();31 public void testFailure() {32 failures.failure("Some error message");33 }34}35import org.assertj.core.internal.Failures;36import org.assertj.core.util.VisibleForTesting;37public class FailuresTest {38 Failures failures = Failures.instance();39 public void testFailure() {40 failures.failure("Some error message");41 }42}43import org.assertj.core.internal.Failures;44import org.assertj.core.util.VisibleForTesting;45public class FailuresTest {46 Failures failures = Failures.instance();47 public void testFailure()

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.RealNumbers;2import org.assertj.core.internal.Numbers;3import org.assertj.core.internal.ComparisonStrategy;4import org.assertj.core.internal.StandardComparisonStrategy;5import org.assertj.core.internal.Failures;6import org.assertj.core.internal.Failures;7import org.assertj.core.internal.TestDescription;8import org.assertj.core.description.Description;9import org.assertj.core.api.Assertions;10import org.assertj.core.api.AssertionInfo;11import org.assertj.core.api.AbstractAssert;12import org.assertj.core.data.Offset;13import org.assertj.core.data.Percentage;14import org.assertj.core.util.VisibleForTesting;15import org.assertj.core.util.CheckReturnValue;16public class RealNumbersTest {17 public void testAssertEqual() {18 RealNumbers numbers = new RealNumbers();19 numbers.assertEqual(info, 8.0, 8.0);20 }21 public void testAssertEqualWithMessage() {22 RealNumbers numbers = new RealNumbers();23 numbers.assertEqual(info, 8.0, 8.0);24 }25 public void testAssertNotEqual() {26 RealNumbers numbers = new RealNumbers();27 numbers.assertNotEqual(info, 8.0, 8.0);28 }29 public void testAssertNotEqualWithMessage() {30 RealNumbers numbers = new RealNumbers();31 numbers.assertNotEqual(info, 8.0, 8.0);32 }33 public void testAssertGreaterThan() {34 RealNumbers numbers = new RealNumbers();35 numbers.assertGreaterThan(info, 8.0, 8.0);36 }37 public void testAssertGreaterThanWithMessage() {38 RealNumbers numbers = new RealNumbers();39 numbers.assertGreaterThan(info, 8.0, 8.0);40 }41 public void testAssertGreaterThanOrEqualTo() {42 RealNumbers numbers = new RealNumbers();43 numbers.assertGreaterThanOrEqualTo(info, 8.0, 8.0);44 }45 public void testAssertGreaterThanOrEqualToWithMessage() {46 RealNumbers numbers = new RealNumbers();47 numbers.assertGreaterThanOrEqualTo(info, 8.0, 8.0);48 }49 public void testAssertLessThan() {50 RealNumbers numbers = new RealNumbers();51 numbers.assertLessThan(info, 8.0

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.RealNumbers;2import org.assertj.core.api.Assertions;3import org.junit.Test;4import org.junit.Before;5import org.junit.After;6public class RealNumbersTest {7 RealNumbers realNumbers;8 public void setUp() throws Exception {9 realNumbers = new RealNumbers();10 }11 public void tearDown() throws Exception {12 }13 public void testAssertIsCloseTo() {14 Assertions.assertThat(1.0).isCloseTo(1.0, Assertions.within(0.5));15 Assertions.assertThat(1.0).isCloseTo(1.0, Assertions.withinPercentage(50));16 }17 public void testAssertIsNotCloseTo() {18 Assertions.assertThat(1.0).isNotCloseTo(1.0, Assertions.within(0.1));19 Assertions.assertThat(1.0).isNotCloseTo(1.0, Assertions.withinPercentage(10));20 }21 public void testAssertIsZero() {22 Assertions.assertThat(0.0).isZero();23 }24 public void testAssertIsNotZero() {25 Assertions.assertThat(1.0).isNotZero();26 }27 public void testAssertIsPositive() {28 Assertions.assertThat(1.0).isPositive();29 }30 public void testAssertIsNotPositive() {31 Assertions.assertThat(-1.0).isNotPositive();32 }33 public void testAssertIsNegative() {34 Assertions.assertThat(-1.0).isNegative();35 }36 public void testAssertIsNotNegative() {37 Assertions.assertThat(1.0).isNotNegative();38 }39}40C:\Users\username\Documents\java>javac -cp .;assertj-core-3.12.2.jar RealNumbersTest.java41C:\Users\username\Documents\java>java -cp .;assertj-core-3.12.2.jar org.junit.runner.JUnitCore RealNumbersTest42OK (1 test)

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.RealNumbers;2public class 1 {3public static void main(String[] args) {4RealNumbers realNumbers = new RealNumbers();5Assertions.assertThat((0.1 + 0.2)).as("0.1 + 0.2 should equal 0.3").isEqualTo(0.3);6}7}8java -cp .;assertj-core-3.12.2.jar 19at org.assertj.core.internal.Failures.failure(Failures.java:89)10at org.assertj.core.internal.Failures.failure(Failures.java:70)11at org.assertj.core.internal.Objects.assertEqual(Objects.java:100)12at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:81)13at 1.main(1.java:9)14import org.assertj.core.internal.RealNumbers;15public class 2 {16public static void main(String[] args) {17RealNumbers realNumbers = new RealNumbers();18Assertions.assertThat((0.1 + 0.2)).as("0.1 + 0.2 should equal 0.3").isEqualTo(0.3);19}20}21java -cp .;assertj-core-3.12.2.jar 222at org.assertj.core.internal.Failures.failure(Failures.java:89)23at org.assertj.core.internal.Failures.failure(Failures.java:70)24at org.assertj.core.internal.Objects.assertEqual(Objects.java:100)25at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:81)26at 2.main(2.java:9)

Full Screen

Full Screen

RealNumbers

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.RealNumbers;2import org.assertj.core.internal.Numbers;3import org.assertj.core.api.Assertions;4import org.assertj.core.api.Assertions;5import org.assertj.core.data.Offset;6import org.assertj.core.data.Percentage;7{8 public static void main(String[] args)9 {10 RealNumbers realNumbers = new RealNumbers();11 Numbers numbers = new Numbers();12 Offset offset = Offset.offset(0.1);13 Percentage percentage = Percentage.withPercentage(0.1);14 Assertions.assertThat(realNumbers.assertEqual(2.0, 2.0)).isTrue();15 Assertions.assertThat(realNumbers.assertNotEqual(2.0, 3.0)).isTrue();16 Assertions.assertThat(realNumbers.assertGreaterThan(2.0, 1.0)).isTrue();17 Assertions.assertThat(realNumbers.assertGreaterThanOrEqualTo(2.0, 2.0)).isTrue();18 Assertions.assertThat(realNumbers.assertLessThan(2.0, 3.0)).isTrue();19 Assertions.assertThat(realNumbers.assertLessThanOrEqualTo(2.0, 2.0)).isTrue();20 Assertions.assertThat(realNumbers.assertIsCloseTo(2.0, 2.1, offset)).isTrue();21 Assertions.assertThat(realNumbers.assertIsCloseTo(2.0, 2.1, percentage)).isTrue();22 Assertions.assertThat(realNumbers.assertIsNotCloseTo(2.0, 3.0, offset)).isTrue();

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.

Run Assertj automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful