Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-121350

Make QCOMPARE use qFuzzyCompare() for QVector3D and other float-containing types

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.6.0
    • Testing: qtestlib
    • None
    • All

      It would be really nice if QCOMPARE would use qFuzzyCompare() for more than just basic comparison of floating point numbers. For example, QVector3D probably should never be compared with == directly; there are other such cases too (like QQuaternion).

      I have the code below (obviously closely related to your definition of QCOMPARE) but I think this is the sort of thing that belongs in your code rather than mine.


      template<typename T>
      bool fuzzyCompare(
          const T &t1, const T &t2, const char *actual, const char *expected,
          const char *file, int line)
      {
          return QTest::compare_helper(qFuzzyCompare(t1, t2), "Compared values are not the same",
              QTest::toString(t1), QTest::toString(t2), actual, expected, file, line);
      }
      
      #define FUZZY_COMPARE(actual, expected) \
      do {\
          if (!fuzzyCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
              return;\
      } while (false)
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            macadder Jason McDonald
            dkfellows Donal Fellows
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes