+#define SIZE(x) (sizeof(x)/sizeof(void*))
+
+static char *tuple2string(Relation *r,Tuple *t) {
+ #define LIMIT 10000
+ static char tmp[10][ LIMIT ];
+ static int i = 0;
+ if ( t == 0 ) {
+ return "(null)";
+ }
+ if ( i >= 10 ) {
+ i = 0;
+ }
+ int n = r->content.type->tostring( r->content.type, t, tmp[i], LIMIT );
+ if ( n == 0 ) {
+ *(tmp[i]) = 0;
+ }
+ return tmp[i++];
+}
+
+static void query_report(Relation *r,Tuple *query) {
+ VectorIndex i;
+ for ( i = 0; i < r->content.table.size; i++ ) {
+ Tuple *t = HashVector_next( &r->content, &i, query );
+ fprintf( stderr, "check %s\n", tuple2string( r, t ) );
+ }
+}
+
+static void query_report_all(Relation *r,Tuple *query[]) {
+ int j;
+ for ( j = 0; query[j]; j++ ) {
+ fprintf( stderr, "query %s\n", tuple2string( r, query[j] ) );
+ query_report( r, query[j] );
+ }
+}
+
+// Report any knocked out tuples from Relation_add or Relation_delete
+// This will also clear and free the result Vector.
+static void knockout_report(Relation *r,Vector *v) {
+ VectorIndex i;
+ if ( v ) {
+ for ( i = 0; i < v->size; i++ ) {
+ Tuple **t = (Tuple **) Vector_next_used( v, &i );
+ fprintf( stderr, "knock %s\n", tuple2string( r, t? *t : 0 ) );
+ }
+ Vector_resize( v, 0, Vector_clear_any, 0 );
+ free( v );
+ }
+}
+
+// Test addition with several tuples, terminated by 0
+static void test_Relation_add(Relation *r,Tuple *query[]) {
+ int j;
+ for ( j = 0; query[j]; j++ ) {
+ fprintf( stderr, "add %s\n", tuple2string( r, query[j] ) );
+ knockout_report( r, Relation_add( r, query[j] ) );
+ }
+}
+
+// Test deletion with several queries, terminated by 0
+static void test_Relation_delete(Relation *r,Tuple *query[]) {
+ int j;
+ for ( j = 0; query[j]; j++ ) {
+ fprintf( stderr, "delete %s\n", tuple2string( r, query[j] ) );
+ knockout_report( r, Relation_delete( r, query[j] ) );
+ }
+}