byte-physics / igortest

Igor Pro Universal Testing Framework
https://docs.byte-physics.de/igor-unit-testing-framework/
BSD 3-Clause "New" or "Revised" License
7 stars 2 forks source link

Empty diff for -0 vs +0 #305

Closed t-b closed 1 year ago

t-b commented 2 years ago

Function Test()

    CHECK_EQUAL_WAVES({0}, {str2num("-0")})
End

gives

•runtest("Procedure")
  Start of test "Unnamed"
  Entering test suite "Procedure"
  Entering test case "Test"
  Assuming equality using mode WAVE_DATA for waves _free_ (0x084b2fa6e0) and _free_ (0x084b2fa660); detailed: Waves difference:
Wave1: _free_ (0x084b2fa6e0)
Wave2: _free_ (0x084b2fa660)
Dimensions|Labels|Value|
----------|------|-----|
: is false. Assertion "CHECK_EQUAL_WAVES({0}, {str2num("-0")})" failed in line 42, procedure "Procedure"
  Leaving test case "Test"
  Failed with 1 errors
  Leaving test suite "Procedure"
  Test finished with 1 errors
  End of test "Unnamed"

I'm mostly posting this here for educational purposes. I don't think we really need to fix the diff. One would also need to lookup if -0 == 0 with IEEE754.

Garados007 commented 2 years ago

This is a really really weird edge case. With CHECK_EQUAL_VAR(0, str2num("-0")) I get no error. After fiddling a bit in C# I got an interesting result:

public static void Main()
{
    double v1 = 0.0;
    double v2 = double.Parse("-0.0");
    // numeric comparison
    Console.WriteLine($"{v1}={v2}: {v1 == v2}");
    // binary comparison
    Console.WriteLine($"{Conv(v1):x16}={Conv(v2):x16}: {Conv(v1) == Conv(v2)}");
}

public static ulong Conv(double value)
=> BitConverter.DoubleToUInt64Bits(value);

// Output:
// 0=-0: True
// 0000000000000000=8000000000000000: False

So I think the problem here is that CHECK_EQUAL_WAVES compares the whole wave with binary comparison which points out the difference between "0" and "-0" and then use numeric comparison to find the different field. To fix this is really difficult because we have to use binary comparison for each field again to find the difference. An alternative way would be to compare the whole wave with numeric comparison in the first place and don't do the binary comparison.

Garados007 commented 2 years ago

We can also do binary comparison in the first place. Then search for the difference with numeric comparison and if we didn't find something we assume that the waves are indeed the same and change the assertion status back to succeeded. This can also enable case-insensitive comparison for text waves.

t-b commented 1 year ago

We will not be fixing this for now. This is too much of an edge case.