}
}
-void test_map(void *pt, void *closure){
+void da_test_map(void *pt, void *closure){
bool *f1 = (bool *)closure;
*f1 = true;
}
memcpy(dap0->base + dap0_size, dap1->base, dap1_size);
}
+//array of Das
+//∃, OR map
+//checks that some Da is present in Da of Das
+
+typedef struct{
+ Da *da;
+ bool found;
+} da_exists_closure;
+
+void da_present(void *da_el, void *closure){
+ Da *da_element = (Da *)da_el;
+ da_exists_closure *dd = (da_exists_closure *)closure;
+ Da *test_element = dd->da;
+ if (dd->found) return;
+ dd->found = da_equal(da_element, test_element);
+ return;
+}//may need to be static?
+
+bool da_equal(Da *da_el, Da *test_el){
+ bool f1 = da_el->base == test_el->base;
+ bool f2 = da_el->end == test_el->end;
+ bool f3 = da_el->size == test_el->size;
+ bool f4 = da_el->element_size == test_el->element_size;
+ return f1 && f2 && f3 && f4;
+}
+
+bool da_exists (Da **dar, int dar_size, Da *dap){
+ da_exists_closure dec;
+ Da *da_first = *dar;
+ dec.da = dap;
+ dec.found = false;
+ da_big_map(dar, dar_size, da_present, &dec);
+ return dec.found;
+}
+
+void da_big_map(Da **dar, int dar_size, void f(void *, void *), void *closure){
+ Da *pt = *dar;
+ int i = 0;
+ while( i < dar_size ){
+ f(pt, closure);
+ pt++;
+ i++;
+ }
+ return;
+}
+
+//∀, AND map
+//checks that all Das are present in Da of Das
+bool da_all (Da **dar, int dar_size, Da **dap){
+ da_exists_closure dec;
+ dec.da = *dap;
+ dec.found = true;
+ int i = 0;
+ while(dec.found && (i < dar_size)){
+ da_big_map(dar, dar_size, da_present, &dec);
+ dec.da++;
+ i++;
+ }
+ return dec.found;
+}
bool da_endq(Da *dap, void *pt);
void da_map(Da *dap, void f(void *, void *), void *closure);
-void test_map(void *pt, void *closure);
+void da_test_map(void *pt, void *closure);
void da_free_elements(Da *dap);
void da_cat(Da *dap_base, Da *dap_cat);
+void da_present(void *da_el, void *closure);
+bool da_equal(Da *da_el, Da *test_el);
+void da_big_map(Da **dar, int dar_size, void f(void *,void*), void *closure);
+bool da_exists(Da **dar, int dar_size, Da *dap);
+bool da_all(Da **dar, int dar_size, Da **dap);
+
#endif
test_da_rebase_0,
test_da_boundq_0,
test_da_map_0,
+ test_da_exists_0,
+ test_da_all_0,
NULL};
char *test_names[] =
{
"test_da_rebase_0",
"test_da_boundq_0",
"test_da_map_0",
+ "test_da_exists_0",
+ "test_da_all_0",
NULL};
// call tests
bool *closure;
bool result = true;
- {//tests map via test_map
+ {//tests map via da_test_map
int i = 0;
while (result && i<4){
- da_map(&dar, test_map, closure);
+ da_map(&dar, da_test_map, closure);
result = *closure;
i++;
*closure = false;
return result;
}
+
+//tests da_exists
+bool test_da_exists_0(){
+ Da *dap0;
+ {
+ da_alloc(dap0, sizeof(char));
+ //char a = 'y';
+ //da_push(dap0, &a);
+ }
+
+ Da *dap1;
+ {
+ da_alloc(dap1, sizeof(char));
+ //char a = 'u';
+ //da_push(dap1, &a);
+ }
+
+ Da *dap2;
+ {
+ da_alloc(dap2, sizeof(char));
+ //char a = 'n';
+ //da_push(dap2, &a);
+ }
+
+ void *darr[3];
+ int dar_size = 0;
+
+ //add dap0, dap1 to darr
+ darr[dar_size] = dap0; dar_size++;
+ darr[dar_size] = dap1; dar_size++;
+
+ //test that dap0 and dap1 exist in darr but not dap2
+ bool f1 = da_exists((Da **)darr, dar_size, dap0);
+ bool f2 = da_exists((Da **)darr, dar_size, dap1);
+ bool f3 = !da_exists((Da **)darr, dar_size, dap2);
+
+ //add dap2 to darr
+ darr[dar_size] = dap2; dar_size++;
+
+ //test that dap2 exists in darr
+ bool f4 = da_exists((Da **)darr, dar_size, dap2);
+
+ return f1 && f2 && f3 && f4;
+}
+
+//tests da_all
+bool test_da_all_0(){
+ return true;
+}
/*
-da_push
-da_pop
da_endq
--da_map Had to put test_map function in da src code...
+-da_map Had to put da_test_map function in da src code...
da_free_elements
da_ints_print
da_strings_print
-da_string_input
da_string_push
-da_cat
+da_exists
+da_all
+
test first
-map
-boundq
+-map
+-boundq
add
-da_exists (OR map, ∃)
-da_all (AND map, ∀)
+-da_exists (OR map, ∃)
+-da_all (AND map, ∀)
*/
bool test_da_rebase_0();
bool test_da_boundq_0();
bool test_da_map_0();
+bool test_da_exists_0();
+bool test_da_all_0();
#endif