void fp_rand(fp_t a) { int bits, digits; rand_bytes((uint8_t *)a, RLC_FP_DIGS * sizeof(dig_t)); RLC_RIP(bits, digits, RLC_FP_BITS); if (bits > 0) { dig_t mask = ((dig_t)1 << (dig_t)bits) - 1; a[RLC_FP_DIGS - 1] &= mask; } while (dv_cmp(a, fp_prime_get(), RLC_FP_DIGS) != RLC_LT) { fp_subn_low(a, a, fp_prime_get()); } }
int main(void) { d_vector(int) v = DV_INIT; int *p; int int3[3] = {1,2,3}; int idx; check_int(v.size, 0); check(v.data == NULL); dv_reserve(&v, 1); check(v.data != NULL); check_int(v.size, 0); check(dv_reserved(v) >= 1); dv_free(v); dv_init(&v); check_int(v.size, 0); check(v.data == NULL); dv_resize(&v, 2); check_int(v.size, 2); check(v.data != NULL); v.data[0] = 50000; v.data[1] = 50000; dv_resize(&v, 1); check_int(v.size, 1); check_int(v.data[0], 50000); check_int(v.data[1], 0); dv_clear(&v); check_int(v.size, 0); check(v.data != NULL); check_int(v.data[0], 0); dv_resize(&v, 3); v.data[0] = 1; v.data[1] = 2; v.data[2] = 3; p = dv_insert_buffer(&v, 1, 2); check(p == &v.data[1]); check_int(v.size, 5); check_int(v.data[0], 1); check_int(v.data[1], 2); check_int(v.data[2], 3); check_int(v.data[3], 2); check_int(v.data[4], 3); dv_resize(&v, 2); p = dv_insert_zeroed(&v, 1, 2); check(p == &v.data[1]); check_int(v.size, 4); check_int(v.data[0], 1); check_int(v.data[1], 0); check_int(v.data[2], 0); check_int(v.data[3], 2); dv_resize(&v, 5); v.data[4] = 4; dv_resize(&v, 1); p = dv_append_buffer(&v, 4); check(p == &v.data[1]); check_int(v.size, 5); check_int(v.data[4], 4); dv_resize(&v, 5); v.data[4] = 4; dv_resize(&v, 1); p = dv_append_zeroed(&v, 4); check(p == &v.data[1]); check_int(v.size, 5); check_int(v.data[4], 0); dv_resize(&v, 1); v.data[0] = 64; dv_append2(&v, int3, 3); check_int(v.size, 4); check_int(v.data[0], 64); check_int(v.data[1], 1); check_int(v.data[2], 2); check_int(v.data[3], 3); dv_resize(&v, 1); dv_append1(&v, 56); check_int(v.size, 2); check_int(v.data[1], 56); check_int(v.data[2], 0); dv_resize(&v, 1); generations = 0; v.data[0] = 64; dv_append(&v, generate()); check_int(generations, 1); check_int(v.size, 4); check_int(v.data[0], 64); check_int(v.data[1], 1); check_int(v.data[2], 2); check_int(v.data[3], 3); dv_resize(&v, 1); v.data[0] = 64; dv_set2(&v, int3, 3); check_int(v.size, 3); check_int(v.data[0], 1); check_int(v.data[1], 2); check_int(v.data[2], 3); dv_resize(&v, 1); generations = 0; v.data[0] = 64; dv_set(&v, generate()); check_int(generations, 1); check_int(v.size, 3); check_int(v.data[0], 1); check_int(v.data[1], 2); check_int(v.data[2], 3); dv_resize(&v, 2); generations = 0; v.data[0] = 64; v.data[1] = 36; dv_insert(&v, 1, generate()); check_int(generations, 1); check_int(v.size, 5); check_int(v.data[0], 64); check_int(v.data[1], 1); check_int(v.data[2], 2); check_int(v.data[3], 3); check_int(v.data[4], 36); dv_resize(&v, 2); generations = 0; v.data[0] = 64; v.data[1] = 36; dv_insert2(&v, 1, int3, 3); check_int(v.size, 5); check_int(v.data[0], 64); check_int(v.data[1], 1); check_int(v.data[2], 2); check_int(v.data[3], 3); check_int(v.data[4], 36); dv_erase(&v, 1, 3); check_int(v.size, 2); check_int(v.data[0], 64); check_int(v.data[1], 36); dv_resize(&v, 3); v.data[0] = 45; v.data[1] = 35; v.data[2] = 45; dv_remove(&v, 45); check_int(v.size, 1); check_int(v.data[0], 35); dv_resize(&v, 3); v.data[0] = 45; v.data[1] = 35; v.data[2] = 45; dv_find(v, 35, &idx); check_int(idx, 1); dv_find(v, 55, &idx); check_int(idx, -1); dv_resize(&v, 3); v.data[0] = 1; v.data[1] = 2; v.data[2] = 3; check(dv_begins_with(v, generate())); check(dv_equals(v, generate())); check(dv_cmp(v, generate()) == 0); check(dv_ends_with(v, generate())); dv_resize(&v, 4); v.data[3] = 5; check(dv_begins_with(v, generate())); check(dv_cmp(v, generate()) > 0); check(!dv_ends_with(v, generate())); v.data[2] = 1; check(!dv_begins_with(v, generate())); check(dv_cmp(v, generate()) < 0); dv_resize(&v, 4); v.data[0] = 5; v.data[1] = 1; v.data[2] = 2; v.data[3] = 3; check(dv_ends_with(v, generate())); v.data[2] = 5; check(!dv_ends_with(v, generate())); return 0; }