From: Ralph Ronnquist Date: Sun, 10 Jul 2022 14:43:04 +0000 (+1000) Subject: expanded tests X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=9e8fceb62721997ca62abfed6080e917bb429eee;p=rrq%2Frrqmisc.git expanded tests --- diff --git a/tests/relationtests.c b/tests/relationtests.c index 127e23a..15c23f2 100644 --- a/tests/relationtests.c +++ b/tests/relationtests.c @@ -32,6 +32,14 @@ static void query_report(relation *r,tuple *query) { } } +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) { @@ -65,6 +73,8 @@ static void test_relation_delete(relation *r,tuple *query[]) { } int main(int argc,char **argv) { + + // AxB tuple *data2[] = { TUPLE( "a", "b" ), TUPLE( "a", "c" ), @@ -77,23 +87,39 @@ int main(int argc,char **argv) { TUPLE( 0, "d" ), 0 }; - int j; - // AxB relation rel2 = RELATION( &stringitem, &stringitem ); + test_relation_add( &rel2, data2 ); query_report( &rel2, 0 ); - for ( j = 0; query2[j]; j++ ) { - fprintf( stderr, "query %s\n", tuple2string( &rel2, query2[j] ) ); - query_report( &rel2, query2[j] ); - } + query_report_all( &rel2, query2 ); test_relation_delete( &rel2, query2 ); // AxBxC + tuple *data3[] = { + TUPLE( "a", "b", "c" ), // *** + TUPLE( "a", "c", "d" ), // *** + TUPLE( "a", "b", "e" ), // => - + TUPLE( "b", "d", "d" ), // + TUPLE( "a", "d", "d" ), // => - + TUPLE( "e", "c", "a" ), // + TUPLE( "f", "b", "d" ), // + 0 + }; + tuple *query3[] = { + TUPLE( "a", 0, "d" ), + TUPLE( 0, 0, "d" ), + TUPLE( 0, "c", 0 ), + TUPLE( "f", "b", "d" ), + 0 + }; relation rel3 = RELATION( &stringitem, &stringitem, &stringitem ); - // AxB -> C - relation_add_constraint( &rel3, 1, 1, 0 ); - // AxC -> B - relation_add_constraint( &rel3, 1, 0, 1 ); + relation_add_constraint( &rel3, 1, 1, 0 ); // AxB -> C + relation_add_constraint( &rel3, 1, 0, 1 ); // AxC -> B + + test_relation_add( &rel3, data3 ); + query_report( &rel3, 0 ); + query_report_all( &rel3, query3 ); + test_relation_delete( &rel3, query3 ); return 0; }