aboutsummaryrefslogtreecommitdiff
path: root/tests/list_check.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-02-08 11:28:35 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:13 +0100
commit1ffb2b7ddb1e8ce4f4fbc5c7f1a13e8533859bb6 (patch)
tree98ef44aeab3aa9b334f4e33dbf48a2de85b3fabd /tests/list_check.c
parent752514ddcf594ee4ec63708ca60f64e9ed786632 (diff)
List debugging
Diffstat (limited to 'tests/list_check.c')
-rw-r--r--tests/list_check.c50
1 files changed, 18 insertions, 32 deletions
diff --git a/tests/list_check.c b/tests/list_check.c
index be427af0..91d7367d 100644
--- a/tests/list_check.c
+++ b/tests/list_check.c
@@ -38,6 +38,8 @@ static int test_lists(int num_items)
RefList *list;
int i;
+ fprintf(stderr, "Testing with %i items.\n", num_items);
+
check = malloc(num_items * sizeof(struct refltemp));
list = reflist_new();
@@ -47,17 +49,22 @@ static int test_lists(int num_items)
int j;
int duplicate = 0;
- h = RANDOM_INDEX;
- k = RANDOM_INDEX;
- l = RANDOM_INDEX;
+ do {
+ 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++;
+ for ( j=0; j<i; j++ ) {
+ if ( (check[j].h == h)
+ && (check[j].k == k)
+ && (check[j].l == l) ) {
+ duplicate++;
+ }
}
- }
+
+ } while ( duplicate );
add_refl(list, h, k, l);
check[i].h = h;
@@ -90,28 +97,7 @@ static int test_lists(int num_items)
}
- 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;
- }
-
- }
-
+ reflist_free(list);
free(check);
return 0;
@@ -122,7 +108,7 @@ int main(int argc, char *argv[])
int i;
for ( i=0; i<100; i++ ) {
- if ( test_lists(random()) ) return 1;
+ if ( test_lists(4096*random()/RAND_MAX) ) return 1;
}
return 0;