use of org.assertj.core.internal.AtPrecisionComparator in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test method should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_types.
@Test
void should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_types() {
// GIVEN
Giant goliath = new Giant();
goliath.name = "Goliath";
goliath.height = 3.0;
Giant goliathTwin = new Giant();
goliathTwin.name = "Goliath";
goliathTwin.height = 3.1;
// THEN
assertThat(goliath).usingRecursiveComparison().withComparatorForType(new AtPrecisionComparator<>(0.2), Double.class).isEqualTo(goliathTwin);
assertThat(goliath).usingRecursiveComparison().withEqualsForType((d1, d2) -> Math.abs(d1 - d2) < 0.2, Double.class).isEqualTo(goliathTwin);
}
use of org.assertj.core.internal.AtPrecisionComparator in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_be_able_to_compare_objects_recursively_using_given_comparator_for_specified_nested_field.
@Test
void should_be_able_to_compare_objects_recursively_using_given_comparator_for_specified_nested_field() {
// GIVEN
Giant goliath = new Giant();
goliath.name = "Goliath";
goliath.height = 3.0;
goliath.home.address.number = 1;
Giant goliathTwin = new Giant();
goliathTwin.name = "Goliath";
goliathTwin.height = 3.1;
goliathTwin.home.address.number = 5;
// THEN
then(goliath).usingRecursiveComparison().withComparatorForFields(new AtPrecisionComparator<>(0.2), "height").withComparatorForFields(new AtPrecisionComparator<>(10), "home.address.number").isEqualTo(goliathTwin);
}
use of org.assertj.core.internal.AtPrecisionComparator in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_fields.
@Test
void should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_fields() {
// GIVEN
Giant goliath = new Giant();
goliath.name = "Goliath";
goliath.height = 3.0;
Giant goliathTwin = new Giant();
goliathTwin.name = "Goliath";
goliathTwin.height = 3.1;
// THEN
then(goliath).usingRecursiveComparison().withComparatorForFields(new AtPrecisionComparator<>(0.2), "height").isEqualTo(goliathTwin);
then(goliath).usingRecursiveComparison().withEqualsForFields((Double d1, Double d2) -> Math.abs(d1 - d2) <= 0.2, "height").isEqualTo(goliathTwin);
}
Aggregations