loa

Virtual machine for the Logic of Assumptions
git clone git://juanmeleiro.mat.br/loa
Log | Files | Refs

schema.test.c (1365B)


      1 #include <stdbool.h>
      2 #include <assert.h>
      3 
      4 #include "schema.h"
      5 
      6 #include "symbol.h"
      7 #include "assoc.h"
      8 
      9 bool
     10 test_name(void)
     11 {
     12 	schema *s = new_schema(intern("test"));
     13 	return (get_name(s) == intern("test"));
     14 }
     15 
     16 bool
     17 test_set_and_get_subschema(void)
     18 {
     19 	schema *s = new_schema(intern("test"));
     20 	schema *sub = new_schema(intern("test"));
     21 	symbol c = intern("c");
     22 	symbol a = intern("a");
     23 
     24 	add_constructor(s, c);
     25 	assign_subschema(s, c, a, sub);
     26 
     27 	return (get_subschema(s, c, a) == sub);
     28 }
     29 
     30 bool
     31 test_set_and_query_leaf(void)
     32 {
     33 	schema *s = new_schema(intern("test"));
     34 	symbol c = intern("c");
     35 	symbol a = intern("a");
     36 
     37 	add_constructor(s, c);
     38 	mark_as_leaf(s, c, a);
     39 
     40 	return takes_leaf(s, c, a);
     41 }
     42 
     43 void
     44 test_leaf_exists(void)
     45 {
     46 	assert(LEAF != NULL);
     47 }
     48 
     49 bool
     50 test_listing_all_keys(void)
     51 {
     52 	schema *s = new_schema(intern("test"));
     53 	add_constructor(s, intern("c"));
     54 	mark_as_leaf(s, intern("c"), intern("l"));
     55 	assign_subschema(s, intern("c"), intern("s"), s);
     56 
     57 	bool good = true;
     58 	size_t num = get_amount_of_required_keys(s, intern("c"));
     59 	symbol *keys = get_required_keys(s, intern("c"));
     60 	for (size_t i = 0; i < num; i++)
     61 		good &= (has_key(s, intern("c"), keys[i]));
     62 
     63 	return good;
     64 }
     65 
     66 int
     67 main()
     68 {
     69 	assert(test_name());
     70 	assert(test_set_and_get_subschema());
     71 	assert(test_set_and_query_leaf());
     72 	test_leaf_exists();
     73 	assert(test_listing_all_keys());
     74 	return 0;
     75 }