WSL/SLF GitLab Repository

Commit 1f41446a authored by Mathias Bavay's avatar Mathias Bavay
Browse files

White spaces clean up, status messages in the stats test

parent 9604a0f1
# simple Script that makes Experimental build with cTest and publie it on CDash with coverage informations.
# simple Script that makes Experimental build with cTest and publie it on CDash with coverage informations.
# This script need to be started be cron. The command for the cron is :
# "ctest -S startScriptCoverage.cmake"
......
# simple Script that makes Nighty build with cTest and publie it on CDash.
# simple Script that makes Nighty build with cTest and publie it on CDash.
# This script need to be started be cron. The command for the cron is :
# "ctest -S startScripNighty.cmake"
......
......@@ -7,7 +7,3 @@ TARGET_LINK_LIBRARIES(stats ${LIBRARIES})
# add the tests
ADD_TEST(stats.smoke stats)
SET_TESTS_PROPERTIES(stats.smoke PROPERTIES LABELS smoke)
//#include <stdlib.h>
#include <cstdlib>
#include <time.h>
#include <meteoio/MeteoIO.h>
......@@ -60,7 +59,10 @@ bool check_sort(const vector<double>& x, const vector<double>& y) {
if(y[index] != Y[ii]) status=false;
}
if(!status) std::cerr << "Sorting of vectors failed\n";
if(status)
std::cout << "Sorting of vectors: success\n";
else
std::cout << "Sorting of vectors: failed\n";
return status;
}
......@@ -78,6 +80,10 @@ bool check_quantiles(const vector<double>& X) {
}
}
if(status)
std::cout << "Quantiles: success\n";
else
std::cout << "Quantiles: failed\n";
return status;
}
......@@ -86,29 +92,37 @@ bool check_basics(const vector<double>& X) {
const double median = Interpol1D::getMedian(X);
const double median_ref = 57.4737;
const bool median_status = IOUtils::checkEpsilonEquality(median, median_ref, 1e-6);
if(!median_status)
std::cerr << setprecision(12) << "Median should be " << median_ref << ", computed " << median << " instead\n";
if(median_status)
std::cout << "Median: success\n";
else
std::cout << setprecision(12) << "Median should be " << median_ref << ", computed " << median << " instead\n";
//MAD
const double mad = Interpol1D::getMedianAverageDeviation(X);
const double mad_ref = 172.4717;
const bool mad_status = IOUtils::checkEpsilonEquality(mad, mad_ref, 1e-6);
if(!mad_status)
std::cerr << setprecision(12) << "MAD should be " << mad_ref << ", computed " << mad << " instead\n";
if(mad_status)
std::cout << "MAD: success\n";
else
std::cout << setprecision(12) << "MAD should be " << mad_ref << ", computed " << mad << " instead\n";
//variance
const double variance = Interpol1D::variance(X);
const double variance_ref = 83038.1246275;
const bool variance_status = IOUtils::checkEpsilonEquality(variance, variance_ref, 1e-6);
if(!variance_status)
std::cerr << setprecision(12) << "Variance should be " << variance_ref << ", computed " << variance << " instead\n";
if(variance_status)
std::cout << "Variance: success\n";
else
std::cout << setprecision(12) << "Variance should be " << variance_ref << ", computed " << variance << " instead\n";
//stddev
const double stddev = Interpol1D::std_dev(X);
const double stddev_ref = 288.163364478;
const bool stddev_status = IOUtils::checkEpsilonEquality(stddev, stddev_ref, 1e-6);
if(!stddev_status)
std::cerr << setprecision(12) << "Stddev should be " << stddev_ref << ", computed " << stddev << " instead\n";
if(stddev_status)
std::cout << "Stddev: success\n";
else
std::cout << setprecision(12) << "Stddev should be " << stddev_ref << ", computed " << stddev << " instead\n";
//weighted mean
const double d1 = 288.1643545;
......@@ -118,9 +132,11 @@ bool check_basics(const vector<double>& X) {
const double m1 = Interpol1D::weightedMean(d1, d2, w1);
const double m2 = Interpol1D::weightedMean(d1, d2, w2);
double wmean_status = true;
if( !IOUtils::checkEpsilonEquality(m1, m1_ref, 1e-6) || !IOUtils::checkEpsilonEquality(m2, m2_ref, 1e-6)) {
std::cerr << setprecision(12) << "Weighted means should be " << m1_ref << " and " << m2_ref;
std::cerr << ", computed " << m1 << " and " << m2 << " instead\n";
if(IOUtils::checkEpsilonEquality(m1, m1_ref, 1e-6) && IOUtils::checkEpsilonEquality(m2, m2_ref, 1e-6))
std::cout << "Weighted mean: success\n";
else {
std::cout << setprecision(12) << "Weighted means should be " << m1_ref << " and " << m2_ref;
std::cout << ", computed " << m1 << " and " << m2 << " instead\n";
wmean_status = false;
}
......@@ -129,9 +145,10 @@ bool check_basics(const vector<double>& X) {
const double vector_mean = Interpol1D::weightedMean(X, weights);
const double mean = Interpol1D::arithmeticMean(X);
const double vector_mean_status = IOUtils::checkEpsilonEquality(vector_mean, mean, 1e-6);
if(!vector_mean_status) {
std::cerr << setprecision(12) << "Vector mean should be " << mean << ", conputed " << vector_mean << " instead\n";
}
if(vector_mean_status)
std::cout << "Vector weighted mean: success\n";
else
std::cout << setprecision(12) << "Vector mean should be " << mean << ", conputed " << vector_mean << " instead\n";
return (mad_status || variance_status || median_status || stddev_status || wmean_status || vector_mean_status);
}
......@@ -140,12 +157,13 @@ bool check_covariance(const vector<double>& x, const vector<double>& y) {
const double cov = Interpol1D::covariance(x, y);
const double cov_ref = -35272.1266148;
if(!IOUtils::checkEpsilonEquality(cov, cov_ref, 1e-6)) {
std::cerr << setprecision(12) << "Covariance should be " << cov_ref << ", conputed " << cov << " instead\n";
return false;
}
const bool status = IOUtils::checkEpsilonEquality(cov, cov_ref, 1e-6);
if(status)
std::cout << "Covariance: success\n";
else
std::cout << setprecision(12) << "Covariance should be " << cov_ref << ", conputed " << cov << " instead\n";
return true;
return status;
}
bool check_derivative(const vector<double>& x, const vector<double>& y) {
......@@ -154,15 +172,19 @@ bool check_derivative(const vector<double>& x, const vector<double>& y) {
Interpol1D::sort(X, Y);
const vector<double> der = Interpol1D::derivative(X, Y);
bool der_status = true;
bool status = true;
for(size_t ii=0; ii<der.size(); ++ii) {
if(!IOUtils::checkEpsilonEquality(der[ii], results[ii], 1e-6)) {
std::cerr << setprecision(12) << "Derivative[" << ii << "] should be " << results[ii] << ", conputed " << der[ii] << " instead\n";
der_status = false;
status = false;
}
}
return der_status;
if(status)
std::cout << "Derivative: success\n";
else
std::cout << "Derivative: failed\n";
return status;
}
int main() {
......@@ -170,15 +192,15 @@ int main() {
//cr_rand_vectors(x, y);
cr_fixed_vectors(x, y);
const bool basics_status = check_basics(x);
const bool sort_status = check_sort(x,y);
const bool quantiles_status = check_quantiles(x);
const bool basics_status = check_basics(x);
const bool covariance_status = check_covariance(x,y);
const bool der_status = check_derivative(x,y);
const bool quantiles_status = check_quantiles(x);
if(!basics_status || !sort_status || !quantiles_status || !covariance_status || !der_status)
throw IOException("Statistical functions error!", AT);
return 0;
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment