Bugzilla – Attachment 152263 Details for
Bug 125978
Unreliable float comparisons in bridgetest
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
bridgetest patch
fix-flaky-bridgetest.diff (text/plain), 2.28 KB, created by
Marcus Tomlinson
on 2019-06-18 08:04:33 UTC
(
hide
)
Description:
bridgetest patch
Filename:
MIME Type:
Creator:
Marcus Tomlinson
Created:
2019-06-18 08:04:33 UTC
Size:
2.28 KB
patch
obsolete
>Description: Add safer float comparisons to bridgetest equals() >Author: Marcus Tomlinson <marcus.tomlinson@canonical.com> >Bug-Ubuntu: https://launchpad.net/bugs/1832360 > >--- a/testtools/source/bridgetest/bridgetest.cxx >+++ b/testtools/source/bridgetest/bridgetest.cxx >@@ -53,6 +53,7 @@ > #include "currentcontextchecker.hxx" > #include "multi.hxx" > #include <memory> >+#include <cmath> > > using namespace osl; > using namespace cppu; >@@ -124,6 +125,9 @@ public: > > static bool equals( const TestElement & rData1, const TestElement & rData2 ) > { >+ const float epsilon_f = 0.00001f; >+ const double epsilon_d = 0.000000000001; >+ > check( rData1.Bool == rData2.Bool, "### bool does not match!" ); > check( rData1.Char == rData2.Char, "### char does not match!" ); > check( rData1.Byte == rData2.Byte, "### byte does not match!" ); >@@ -133,8 +137,8 @@ static bool equals( const TestElement & rData1, const TestElement & rData2 ) > check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" ); > check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" ); > check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" ); >- check( rData1.Float == rData2.Float, "### float does not match!" ); >- check( rData1.Double == rData2.Double, "### double does not match!" ); >+ check( fabs( rData1.Float - rData2.Float ) < epsilon_f, "### float does not match!" ); >+ check( fabs( rData1.Double - rData2.Double ) < epsilon_d, "### double does not match!" ); > check( rData1.Enum == rData2.Enum, "### enum does not match!" ); > check( rData1.String == rData2.String, "### string does not match!" ); > check( rData1.Interface == rData2.Interface, "### interface does not match!" ); >@@ -149,8 +153,8 @@ static bool equals( const TestElement & rData1, const TestElement & rData2 ) > rData1.ULong == rData2.ULong && > rData1.Hyper == rData2.Hyper && > rData1.UHyper == rData2.UHyper && >- rData1.Float == rData2.Float && >- rData1.Double == rData2.Double && >+ fabs( rData1.Float - rData2.Float ) < epsilon_f && >+ fabs( rData1.Double - rData2.Double ) < epsilon_d && > rData1.Enum == rData2.Enum && > rData1.String == rData2.String && > rData1.Interface == rData2.Interface &&
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 125978
: 152263