Skip to content

Support for comparing floats for equality in unit test ==> AssertEqualFloat(expect, actual, abs_delta) ? #244

Closed
@RobTillaart

Description

@RobTillaart

Some of my libraries use float math and errors add up when doing a lot of float math.
e.g https://github.com/RobTillaart/AverageAngle/runs/1543777648?check_suite_focus=true

To test for equality for a float output I typically use the following working construct

  fprintf(stderr, "getTotalLength()\n");
  float diff = abs(10 - aa.getTotalLength());
  assertMoreOrEqual(0.2, diff);

however I would prefer a oneliner

  AssertEqualFloat(10,  aa.getTotalLength(), 0.2);

output should be something like one of the three

AssertEqualFloat  10 == aa.getTotalLength()  +- 0.2
AssertEqualFloat  10 +- 0.2 == aa.getTotalLength()
AssertEqualFloat  10- 0.2 <  aa.getTotalLength() < 10 + 0.2

Maybe it should be called AssertAlmostEqual(...)

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestunittest libsThe assert / assure / unittest reporting apparatus is affected

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions