ex-1: add median test

This commit is contained in:
Michele Guerini Rocco 2020-03-24 01:41:45 +00:00
parent 0ee7f9adb3
commit 9aadcbf8a7

View File

@ -3,6 +3,7 @@
#include <math.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_histogram.h>
#include <gsl/gsl_statistics_double.h>
#include "landau.h"
#include "tests.h"
@ -140,13 +141,29 @@ int main(int argc, char** argv) {
// print the results
fprintf(stderr, "\n\n# FWHM comparison\n");
double fwhm_e = numeric_fwhm(min, max, mode_e);
fprintf(stderr, "\n# Results\n");
fprintf(stderr, "expected FWHM: %.7f\n", fwhm_e);
fprintf(stderr, "observed FWHM: %.3f\n", fwhm_o);
// print the counts
// gsl_histogram_fprintf(stdout, hist, "%g", "%g");
/* Median comparison
*
* Compute the median of the sample
* and compare it with QDF(1/2).
*/
fprintf(stderr, "\n\n# Median comparison\n");
double med_e = landau_qdf(0.5);
double med_o = gsl_stats_median_from_sorted_data(
sample, // sorted data
1, // array stride
samples); // number of elements
// print the results
fprintf(stderr, "\n# Results\n");
fprintf(stderr, "expected median: %.7f\n", med_e);
fprintf(stderr, "observed median: %.7f\n", med_o);
// clean up and exit
gsl_histogram_free(hist);