aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-05-15 16:58:24 +0200
committerThomas White <taw@physics.org>2019-05-15 16:58:24 +0200
commita68c03522a0eafadd1cdcb635896c4be76e665c8 (patch)
tree3a94d02b557c99852720648bc5f550100261337b /tests
parent5d8452c9220c82fed9022818d3bde62f804b373d (diff)
Complete implementation of Spectrum API
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/spectrum_check.c77
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index af22977e..192913ce 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -87,3 +87,8 @@ add_executable(rational_check rational_check.c)
target_include_directories(rational_check PRIVATE ${COMMON_INCLUDES})
target_link_libraries(rational_check ${COMMON_LIBRARIES})
add_test(rational_check rational_check)
+
+add_executable(spectrum_check spectrum_check.c)
+target_include_directories(spectrum_check PRIVATE ${COMMON_INCLUDES})
+target_link_libraries(spectrum_check ${COMMON_LIBRARIES})
+add_test(spectrum_check spectrum_check)
diff --git a/tests/spectrum_check.c b/tests/spectrum_check.c
new file mode 100644
index 00000000..7d37689d
--- /dev/null
+++ b/tests/spectrum_check.c
@@ -0,0 +1,77 @@
+/*
+ * spectrum_check.c
+ *
+ * Check that Spectrum object works
+ *
+ * Copyright © 2019 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
+ *
+ * Authors:
+ * 2019 Thomas White <taw@physics.org>
+ *
+ * This file is part of CrystFEL.
+ *
+ * CrystFEL is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CrystFEL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CrystFEL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include <spectrum.h>
+#include <utils.h>
+
+static int check_integral(Spectrum *s, int nsamp)
+{
+ double min, max, step;
+ int i;
+ double area = 0.0;
+
+ spectrum_get_range(s, &min, &max);
+ fprintf(stderr, "bounds: %e %e\n", min, max);
+ step = (max-min)/nsamp;
+ for ( i=0; i<=nsamp; i++ ) {
+ double x = min+i*step;
+ double y = spectrum_get_density_at_k(s, x);
+ area += y * step;
+ }
+ fprintf(stderr, "Total area + %f\n", area);
+ if ( area > 1.1 ) return 1;
+ if ( area < 0.9 ) return 1;
+ return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+ Spectrum *s;
+ struct gaussian gauss;
+ int r = 0;
+
+ s = spectrum_new();
+ gauss.kcen = ph_eV_to_k(9000);
+ gauss.sigma = ph_eV_to_k(100);
+ gauss.height = 1.0;
+ spectrum_set_gaussians(s, &gauss, 1);
+ r += check_integral(s, 100);
+ spectrum_free(s);
+
+ return r;
+}