summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-11-24 22:10:46 (GMT)
committerMarius Kintel <marius@kintel.net>2011-11-24 22:10:46 (GMT)
commit42d709908950790302f2f0bfc24267b77d6716c0 (patch)
treedf1eae5dabb2f2aecfaba217e65d727a16c032c8
parent3f0a991a3da991ce9672fe92cffa157e194abab9 (diff)
Attempt to batte floating point rounding differences for testing purposes
-rw-r--r--src/value.cc13
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/regression/echotest/builtin-tests-expected.txt2
-rw-r--r--tests/regression/echotest/dim-all-expected.txt12
4 files changed, 21 insertions, 7 deletions
diff --git a/src/value.cc b/src/value.cc
index ab78c2a..5ea766c 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -363,7 +363,20 @@ std::string Value::toString() const
<< ']';
break;
case NUMBER:
+#ifdef OPENSCAD_TESTING
+ // Quick and dirty hack to work around floating point rounding differences
+ // across platforms for testing purposes.
+ {
+ std::stringstream tmp;
+ tmp.precision(16);
+ tmp << this->num;
+ std::string tmpstr = tmp.str();
+ if (tmpstr.size() > 16) tmpstr.erase(16);
+ stream << tmpstr;
+ }
+#else
stream << this->num;
+#endif
break;
case BOOL:
stream << (this->b ? "true" : "false");
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 15f168f..6de3d93 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -199,6 +199,7 @@ include_directories(${CGAL_INCLUDE_DIRS})
include_directories(../src)
add_definitions(-DOPENSCAD_VERSION=test -DOPENSCAD_YEAR=2011 -DOPENSCAD_MONTH=10)
+add_definitions(-DOPENSCAD_TESTING)
set(CORE_SOURCES
tests-common.cc
diff --git a/tests/regression/echotest/builtin-tests-expected.txt b/tests/regression/echotest/builtin-tests-expected.txt
index e8b2027..0e8d1a7 100644
--- a/tests/regression/echotest/builtin-tests-expected.txt
+++ b/tests/regression/echotest/builtin-tests-expected.txt
@@ -1 +1 @@
-ECHO: 3.141592653589793
+ECHO: 3.14159265358979
diff --git a/tests/regression/echotest/dim-all-expected.txt b/tests/regression/echotest/dim-all-expected.txt
index 74044a1..d8c3269 100644
--- a/tests/regression/echotest/dim-all-expected.txt
+++ b/tests/regression/echotest/dim-all-expected.txt
@@ -1,16 +1,16 @@
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
-ECHO: linearX = 51.44957554275265
+ECHO: linearX = 51.4495755427526
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
-ECHO: linearY = 29.13025467434841
+ECHO: linearY = 29.1302546743484
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
-ECHO: aligned = 60.00000000000001
+ECHO: aligned = 60.0000000000000
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
-ECHO: ordinateX = -49.17542445724735
+ECHO: ordinateX = -49.175424457247
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
-ECHO: ordinateY = 30.86974532565159
+ECHO: ordinateY = 30.8697453256515
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
ECHO: radius = 60
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
ECHO: diameter = 120
WARNING: Unsupported DXF Entity `LEADER' (1) in `dim-all.dxf'.
-ECHO: arc = 59.03624346792648
+ECHO: arc = 59.0362434679264
contact: Jan Huwald // Impressum