Skip to content

Invalid conversion when using delta in float comparison #999

@JosRoseboom

Description

@JosRoseboom

The recipe:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run --define rewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE --define rewrite.activeRecipes=org.openrewrite.java.testing.assertj.Assertj --define rewrite.exportDatatables=true

changes

Assertions.assertEquals(7f, rect.getHeight(), 0);

to the invalid:

assertThat(rect.getHeight()).as(0).isEqualTo(7f);

A delta of 0 might not make sense, but is valid. A delta that makes sense works fine:

Assertions.assertEquals(7f, rect.getHeight(), 0.01f);

becomes the expected:

assertThat(rect.getHeight()).isCloseTo(7f, within(0.01f));

However, if the delta to the float comparison is given as double (which is valid):

Assertions.assertEquals(7f, rect.getHeight(), 0.01);

it is converted to the invalid:

assertThat(rect.getHeight()).isCloseTo(7f, within(0.01));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions