git.ucc.asn.au
/
ipdf
/
code.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add #define to transform Object bounds on the fly
[ipdf/code.git]
/
src
/
tests
/
realops.cpp
diff --git
a/src/tests/realops.cpp
b/src/tests/realops.cpp
index
400ce86
..
dd45aa8
100644
(file)
--- a/
src/tests/realops.cpp
+++ b/
src/tests/realops.cpp
@@
-1,16
+1,20
@@
+/**
+ * Test mathematical operations on the Real type and consistency with double
+ */
+
#include "main.h"
#include "real.h"
using namespace std;
using namespace IPDF;
#include "main.h"
#include "real.h"
using namespace std;
using namespace IPDF;
-#define TEST_CASES 100
+#define TEST_CASES 100
0
static double g_totalerror = 0;
static double g_totalerror = 0;
-bool NotEqual(double a, double b, double threshold=1e-
1
)
+bool NotEqual(double a, double b, double threshold=1e-
4
)
{
{
- double error =
(fabs(a-b) > threshold
);
+ double error =
fabs(a-b
);
g_totalerror += error;
return (error > threshold);
}
g_totalerror += error;
return (error > threshold);
}
@@
-18,12
+22,14
@@
bool NotEqual(double a, double b, double threshold=1e-1)
int main(int argc, char ** argv)
{
srand(time(NULL));
int main(int argc, char ** argv)
{
srand(time(NULL));
+ DebugRealInfo();
unsigned failures = 0;
for (unsigned i = 0; i < TEST_CASES; ++i)
{
unsigned failures = 0;
for (unsigned i = 0; i < TEST_CASES; ++i)
{
- double da = (double)(rand()%100 + 1) / (double)(rand()%100 + 1);
- double db = (double)(rand()%100 + 1) / (double)(rand()%100 + 1);
+ //Debug("Test %u of %u", i, TEST_CASES);
+ double da = (double)(rand() + 1) / (double)(rand() + 1);
+ double db = (double)(rand() + 1) / (double)(rand() + 1);
if (rand() % 2 == 0)
da = -da;
if (rand() % 2 == 0)
da = -da;
@@
-110,7
+116,18
@@
int main(int argc, char ** argv)
{
failures++;
Warn("a /= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
{
failures++;
Warn("a /= b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
+ }
+ if (NotEqual(Double(a*0.0 + 1.0), da*0.0 + 1.0))
+ {
+ failures++;
+ Warn("a * 0 = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
}
}
+
+ if (NotEqual(Double(a=b), da=db))
+ {
+ failures++;
+ Warn("a = b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop));
+ }
if (failures > old_failures)
{
if (failures > old_failures)
{
UCC
git Repository :: git.ucc.asn.au