END_TEST START_TEST (test_frequency_of_int_partitions_by_k_n4) { double e, ep; e = 0.000001; int n, tp, i, ip; d_array * probs; probs = init_d_array(1); n = 4; tp = frequency_of_int_partitions_by_k(n, probs); ep = 1.0; ip = 5; ck_assert_msg((almost_equal(tp, ep, e) != 0), "total probability is %lf, not %lf", tp, ep); ck_assert_int_eq(probs->length, n); i = 0; ep = 1/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 1; ep = 2/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 2; ep = 1/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 3; ep = 1/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); free_d_array(probs); }
END_TEST START_TEST (test_get_d_array) { int size; d_array * v; size = 1; v = init_d_array(size); append_d_array(v, 0.1); ck_assert_msg((get_d_array(v, 0) == 0.1), "`d_array` element is %lf, expecting %lf", get_d_array(v, 0), 0.1); append_d_array(v, 0.2); ck_assert_msg((get_d_array(v, 1) == 0.2), "`d_array` element is %lf, expecting %lf", get_d_array(v, 1), 0.2); }
END_TEST START_TEST (test_get_d_array_fail) { int size; d_array * v; size = 1; v = init_d_array(size); append_d_array(v, 0.1); get_d_array(v, 1); // SIGABRT }
END_TEST START_TEST (test_cumulative_frequency_of_int_partitions_by_k_n3) { double e, ep; e = 0.000001; int n, tp, i; d_array * probs; probs = init_d_array(1); n = 3; tp = cumulative_frequency_of_int_partitions_by_k(n, probs); ep = 1.0; ck_assert_msg((almost_equal(tp, ep, e) != 0), "total probability is %lf, not %lf", tp, ep); ck_assert_int_eq(probs->length, n); i = 0; ep = 0.333333333; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 1; ep = 0.666666666; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 2; ep = 1.0; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); free_d_array(probs); }
END_TEST START_TEST (test_get_doubles) { int ret; s_array * search_strings; i_array * indices; d_array * dest; search_strings = init_s_array(1); indices = init_i_array(1); dest = init_d_array(1); append_s_array(search_strings, "foo"); append_s_array(search_strings, "0.345"); append_s_array(search_strings, "156.345"); append_s_array(search_strings, "bar"); append_s_array(search_strings, "1.23e3"); append_s_array(search_strings, "1.2"); append_i_array(indices, 1); append_i_array(indices, 2); append_i_array(indices, 4); ret = get_doubles(search_strings, indices, dest); ck_assert_int_eq(ret, 0); ck_assert_int_eq(dest->length, 3); ck_assert_msg((almost_equal(get_d_array(dest, 0), 0.345, 0.000001)), "extracted double is %lf, expected %lf", get_d_array(dest, 0), 0.345); ck_assert_msg((almost_equal(get_d_array(dest, 1), 156.345, 0.000001)), "extracted double is %lf, expected %lf", get_d_array(dest, 1), 156.345); ck_assert_msg((almost_equal(get_d_array(dest, 2), 1230.0, 0.000001)), "extracted double is %lf, expected %lf", get_d_array(dest, 2), 1230.0); append_i_array(indices, 0); ret = get_doubles(search_strings, indices, dest); ck_assert_int_eq(ret, 1); }