/* * Test node removal: p = power_product to remove */ static void test_remove(rba_buffer_t *b, pprod_t *p) { uint32_t i, j; bool new_node; if (p == empty_pp) { printf("test remove: empty product\n"); } else { printf("test remove: x%"PRId32"\n", var_of_pp(p)); } i = rba_find_node(b, p); if (i != 0) { q_clear(&b->mono[i].coeff); // get_node must be called first to setup b->stack j = rba_get_node(b, p, &new_node); if (j != i && new_node) { printf("Error in test_removed: get_node failed\n"); fflush(stdout); exit(1); } rba_delete_node(b, i); j = rba_find_node(b, p); if (j != 0) { printf("Error in test_remove: removal failed\n"); fflush(stdout); exit(1); } check_tree(b); } }
/* * Power product p */ static void print_bv_pprod(FILE *f, pprod_t *p) { assert(! pp_is_empty(p) && p != end_pp); if (pp_is_var(p)) { print_bvvar(f, var_of_pp(p)); } else { print_bv_product(f, p); } }
static void print_pprod0(FILE *f, pprod_t *p) { if (pp_is_var(p)) { fprintf(f, "x_%"PRId32, var_of_pp(p)); } else if (pp_is_empty(p)) { fprintf(f, "1"); } else { print_varexp_array(f, p->prod, p->len); } }
static void print_pprod(FILE *f, pprod_t *p) { fprintf(f, "pprod %p\n", p); if (pp_is_var(p)) { fprintf(f, " var pp = [x_%"PRId32"]\n", var_of_pp(p)); } else if (pp_is_empty(p)) { fprintf(f, " empty\n"); } else { fprintf(f, " len = %"PRIu32"\n", p->len); fprintf(f, " degree = %"PRIu32"\n", p->degree); fprintf(f, " product = "); print_varexp_array(f, p->prod, p->len); fprintf(f, "\n"); } }
/* * Test node addition: p = power_product to add */ static void test_add(rba_buffer_t *b, pprod_t *p) { uint32_t i, j, k; bool new_node; if (p == empty_pp) { printf("test add: empty product\n"); } else { printf("test add: x%"PRId32"\n", var_of_pp(p)); } i = rba_find_node(b, p); j = rba_get_node(b, p, &new_node); k = rba_find_node(b, p); if (j != k) { printf("Error in test_add: find after get failed\n"); fflush(stdout); exit(1); } if (i == 0 && !new_node) { printf("Error in test_add: expected a new node\n"); fflush(stdout); exit(1); } if (i != 0) { if (new_node) { printf("Error in test_add: not expecting a new node\n"); fflush(stdout); exit(1); } if (j != i) { printf("Error in test_add: get returned an unexpected node\n"); fflush(stdout); exit(1); } } check_tree(b); }