X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Ftests%2Frealops.cpp;h=4669f599591d684eb80ccd6cc205dc9273d5c98c;hp=dd45aa8dbd58a36f27bdaae9ff6bdc100144808b;hb=2d12d37f1657d6aef9bb80d735b6c7022aecba6e;hpb=1d179b93f6a1b2a4fe3823c26fba862c24bc5d6e diff --git a/src/tests/realops.cpp b/src/tests/realops.cpp index dd45aa8..4669f59 100644 --- a/src/tests/realops.cpp +++ b/src/tests/realops.cpp @@ -4,6 +4,7 @@ #include "main.h" #include "real.h" +#include "progressbar.h" using namespace std; using namespace IPDF; @@ -25,8 +26,12 @@ int main(int argc, char ** argv) DebugRealInfo(); unsigned failures = 0; + Real acumulate(0); + double dacumulate = 0; + for (unsigned i = 0; i < TEST_CASES; ++i) { + ProgressBar(i, TEST_CASES, 50); //Debug("Test %u of %u", i, TEST_CASES); double da = (double)(rand() + 1) / (double)(rand() + 1); double db = (double)(rand() + 1) / (double)(rand() + 1); @@ -129,6 +134,49 @@ int main(int argc, char ** argv) Warn("a = b = %f should be %f, a before op was %f", Double(a), da, Double(abeforeop)); } + if (NotEqual(Double(-a), -da)) + { + failures++; + Warn("-a = %f should be %f, a before op was %f", Double(-a), -da, Double(abeforeop)); + } + + if (NotEqual(Double(Sqrt(a)), Sqrt(da))) + { + failures++; + Warn("Sqrt(a) = %f should be %f, a before op was %f", Double(Sqrt(a)), Sqrt(da), Double(abeforeop)); + } + + if (NotEqual(Double(a), da)) + { + failures++; + Warn("a = %f, should be %f, a before ops was %f", Double(a), da, Double(abeforeop)); + } + + switch (rand() % 4) + { + case 0: + acumulate += a; + dacumulate += da; + break; + case 1: + acumulate -= a; + dacumulate -= da; + break; + case 2: + acumulate *= a; + dacumulate *= da; + break; + case 3: + acumulate /= a; + dacumulate /= da; + break; + } + if (NotEqual(Double(acumulate), dacumulate)) + { + Warn("Accumulated result %.30lf vs %.30lf is wrong", Double(acumulate), dacumulate); + failures++; + } + if (failures > old_failures) { Error("%u failures on case %u da = %f, db = %f, a = %f, b = %f, aa = %f, bb = %f", failures-old_failures, i, da, db, Double(a), Double(b), Double(aa), Double(bb)); @@ -137,7 +185,10 @@ int main(int argc, char ** argv) #endif } } - Debug("Completed %u test cases with total of %u operations, %u failures", TEST_CASES, 12*TEST_CASES, failures); + Debug("Completed %u test cases with total of %u operations, %u failures", TEST_CASES, 18*TEST_CASES, failures); Debug("Total accumulated difference between Real and Double operations was %f", g_totalerror); + Debug("Real: %.40lf", Double(acumulate)); + Debug("Doub: %.40lf", dacumulate); + Debug("Diff: %.40lf", Double(acumulate) - dacumulate); }