X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Ftests%2Frealtofloat.cpp;h=c475ea9e50bfe662307bd25e9c8558dcdbe7203e;hp=b09bd4947bb06e02da338d42ca3861f0ca5aa743;hb=888817a67a9d840be66b52811b01eb77f10ff3e6;hpb=32cd67ec48271c176eba218e082fcf5824aa8e6c diff --git a/src/tests/realtofloat.cpp b/src/tests/realtofloat.cpp index b09bd49..c475ea9 100644 --- a/src/tests/realtofloat.cpp +++ b/src/tests/realtofloat.cpp @@ -1,9 +1,26 @@ #include "main.h" -float test = 1e4; +#include +float test_min = 0; +float test_max = 1e-6; +unsigned test_count = 100; +float error_thresh = (test_max - test_min)/1e1; int main(int argc, char ** argv) { - Real r(test); - Debug("test float %.20f", test); - Debug("test real %.20f", Float(r)); + Debug("TEST STARTING - Comparing Float(Real(test)) for %u trials between %.20f and %.20f", test_count, test_min, test_max); + float error; + for (unsigned i = 0; i < test_count; ++i) + { + float test = test_min + (test_max-test_min)*((float)(rand() % (int)1e6)/1e6); + Real real(test); + float thiserror = abs(test - Float(real)); + error += thiserror; + Debug("#%u: |test %.20f - real %.20f| = %.20f [mean %f]", i, test, Float(real), thiserror, error/(i+1)); + } + + if (error/test_count > error_thresh) + { + Fatal("TEST FAILED - Average error %.20f exceeds threshold %.20f", error/test_count, error_thresh); + } + Debug("TEST SUCCEEDED - Average error %.20f is %f percent of range", error/test_count, 1e2*(error/test_count) / (test_max - test_min)); return 0; }