aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-02-07 17:30:20 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:13 +0100
commitb53f133381ef6ffa9f7ecefbf4d134d55ad94455 (patch)
tree8d74e647af300185d71f47c1746ef62cd635005b /tests
parent58addb645ea760b701feb489a7efe4500082a591 (diff)
Add unit test for reflist
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore4
-rw-r--r--tests/list_check.c129
2 files changed, 133 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 00000000..3c726461
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,4 @@
+*.o
+.deps
+list_check
+.dirstamp
diff --git a/tests/list_check.c b/tests/list_check.c
new file mode 100644
index 00000000..be427af0
--- /dev/null
+++ b/tests/list_check.c
@@ -0,0 +1,129 @@
+/*
+ * list_check.c
+ *
+ * Unit test for the reflection list module
+ *
+ * (c) 2011 Thomas White <taw@physics.org>
+ *
+ * Part of CrystFEL - crystallography with a FEL
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "../src/reflist.h"
+
+
+struct refltemp {
+ signed int h;
+ signed int k;
+ signed int l;
+ int del;
+ int dup;
+};
+
+#define RANDOM_INDEX (128*random()/RAND_MAX - 256*random()/RAND_MAX)
+
+
+static int test_lists(int num_items)
+{
+ struct refltemp *check;
+ RefList *list;
+ int i;
+
+ check = malloc(num_items * sizeof(struct refltemp));
+ list = reflist_new();
+
+ for ( i=0; i<num_items; i++ ) {
+
+ signed int h, k, l;
+ int j;
+ int duplicate = 0;
+
+ h = RANDOM_INDEX;
+ k = RANDOM_INDEX;
+ l = RANDOM_INDEX;
+
+ for ( j=0; j<i; j++ ) {
+ if ( (check[j].h == h)
+ && (check[j].k == k)
+ && (check[j].l == l) ) {
+ duplicate++;
+ }
+ }
+
+ add_refl(list, h, k, l);
+ check[i].h = h;
+ check[i].k = k;
+ check[i].l = l;
+ check[i].del = 0;
+ check[i].dup = duplicate;
+
+ }
+
+ for ( i=0; i<num_items; i++ ) {
+
+ signed int h, k, l;
+ Reflection *refl;
+
+ h = check[i].h;
+ k = check[i].k;
+ l = check[i].l;
+
+ refl = find_refl(list, h, k, l);
+ if ( refl == NULL ) {
+ fprintf(stderr, "Couldn't find %3i %3i %3i\n", h, k, l);
+ return 1;
+ }
+
+ if ( i<num_items/2 ) {
+ delete_refl(refl);
+ check[i].del = 1;
+ }
+
+ }
+
+ for ( i=0; i<num_items/2; i++ ) {
+
+ signed int h, k, l;
+ Reflection *refl;
+
+ h = check[i].h;
+ k = check[i].k;
+ l = check[i].l;
+
+ refl = find_refl(list, h, k, l);
+ if ( refl == NULL ) {
+ fprintf(stderr, "Couldn't find %3i %3i %3i\n", h, k, l);
+ return 1;
+ }
+
+ if ( i<num_items/2 ) {
+ delete_refl(refl);
+ check[i].del = 1;
+ }
+
+ }
+
+ free(check);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+
+ for ( i=0; i<100; i++ ) {
+ if ( test_lists(random()) ) return 1;
+ }
+
+ return 0;
+}