/* * Test hash consing: add a random triple in table */ static void test_random_triple(dl_vartable_t *table) { dl_triple_t *check; dl_triple_t test; int32_t x, y; test.target = random_vertex(6); test.source = random_vertex(6); q_init(&test.constant); random_rational(&test.constant); if (test.target == test.source) { test.target = nil_vertex; test.source = nil_vertex; } printf("Test: add triple "); print_dl_triple(&test); printf("\n"); x = get_dl_var(table, &test); printf(" ---> var = %"PRId32"\n", x); check = dl_var_triple(table, x); if (check->target == test.target && check->source == test.source && q_eq(&check->constant, &test.constant)) { printf("Checking descriptor: OK\n"); } else { printf("BUG: invalid descriptor for var %"PRId32"\n", x); fflush(stdout); exit(1); } y = get_dl_var(table, &test); if (x == y) { printf("Checking hash-consing: OK\n"); } else { printf("BUG: hash-consing fails for var %"PRId32"\n", x); fflush(stdout); exit(1); } printf("\n"); q_clear(&test.constant); }
/* * Tests */ int main(void) { rational_t alpha; uint32_t n; int32_t v; init_rationals(); q_init(&alpha); init_poly_buffer(&buffer); printf("--- Init ---\n"); print_poly_buffer_details(&buffer); reset_poly_buffer(&buffer); printf("--- Reset ---\n"); print_poly_buffer_details(&buffer); normalize_poly_buffer(&buffer); printf("--- Normalize ---\n"); print_poly_buffer_details(&buffer); reset_poly_buffer(&buffer); printf("--- Reset ---\n"); print_poly_buffer_details(&buffer); random_rational(&alpha); poly_buffer_add_monomial(&buffer, 2, &alpha); printf("--- Add monomial x!2 * alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_add_const(&buffer, &alpha); printf("--- Add constant alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_add_monomial(&buffer, 1, &alpha); printf("--- Add monomial x!1 * alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_sub_monomial(&buffer, 2, &alpha); printf("--- Sub monomial x!2 * alpha ---\n"); print_poly_buffer_details(&buffer); normalize_poly_buffer(&buffer); printf("--- Normalize ---\n"); print_poly_buffer_details(&buffer); reset_poly_buffer(&buffer); printf("--- Reset ---\n"); print_poly_buffer_details(&buffer); random_rational(&alpha); poly_buffer_sub_monomial(&buffer, 2, &alpha); printf("--- Sub monomial x!2 * alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_sub_const(&buffer, &alpha); printf("--- Sub constant alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_add_monomial(&buffer, 1, &alpha); printf("--- Add monomial x!1 * alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_sub_monomial(&buffer, 2, &alpha); printf("--- Sub monomial x!2 * alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_add_const(&buffer, &alpha); printf("--- Add constant alpha ---\n"); print_poly_buffer_details(&buffer); poly_buffer_add_var(&buffer, 3); printf("--- Add var x!3 ---\n"); print_poly_buffer_details(&buffer); poly_buffer_sub_var(&buffer, 3); printf("--- Sub var x!3 ---\n"); print_poly_buffer_details(&buffer); normalize_poly_buffer(&buffer); printf("--- Normalize ---\n"); print_poly_buffer_details(&buffer); reset_poly_buffer(&buffer); for (n=0; n<400; n++) { v = random() % 200; random_rational(&alpha); poly_buffer_add_monomial(&buffer, v, &alpha); } printf("--- 400 random monomials ---\n"); print_poly_buffer_details(&buffer); normalize_poly_buffer(&buffer); printf("--- Normalize ---\n"); print_poly_buffer_details(&buffer); delete_poly_buffer(&buffer); q_clear(&alpha); cleanup_rationals(); return 0; }