Beispiel #1
0
END_TEST

START_TEST (test_summarize_stat_samples_p2_n5) {
    int i;
    s_array * paths;
    s_array * paths_used;
    c_array * line_buffer;
    i_array * stat_indices;
    sample_sum_array * ss_array;
    d_array * means;
    d_array * std_devs;
    d_array * exp_means;
    d_array * exp_std_devs;
    int num_to_sample;
    int expected_num_cols;
    expected_num_cols = 6;
    num_to_sample = 5;
    paths = init_s_array(1);
    paths_used = init_s_array(1);
    line_buffer = init_c_array(1023);
    stat_indices = init_i_array(4);
    ss_array = init_sample_sum_array(4);
    means = init_d_array(1);
    std_devs = init_d_array(1);
    exp_means = init_d_array(1);
    exp_std_devs = init_d_array(1);
    append_s_array(paths, "data/test_parameter_stat_samples.txt");
    append_s_array(paths, "data/test_parameter_stat_samples2.txt");
    for (i = 2; i < expected_num_cols; i++) {
        append_i_array(stat_indices, i);
    }
    summarize_stat_samples(paths, line_buffer, stat_indices, ss_array, means,
            std_devs, num_to_sample, expected_num_cols, paths_used);
    ck_assert_int_eq(means->length, stat_indices->length);
    ck_assert_int_eq(std_devs->length, stat_indices->length);
    ck_assert_int_eq(ss_array->a[0]->n, num_to_sample);
    ck_assert_msg((s_arrays_equal(paths, paths_used) != 0),
            "paths used do not match input paths");
    append_d_array(exp_means, 0.222);
    append_d_array(exp_means, 0.218);
    append_d_array(exp_means, 4.2);
    append_d_array(exp_means, 3.6);
    append_d_array(exp_std_devs, 0.1281405);
    append_d_array(exp_std_devs, 0.0130384);
    append_d_array(exp_std_devs, 3.962323);
    append_d_array(exp_std_devs, 1.67332);
    ck_assert_msg((d_arrays_equal(means, exp_means, 0.000001) != 0),
            "unexpected means");
    ck_assert_msg((d_arrays_equal(std_devs, exp_std_devs, 0.000001) != 0),
            "unexpected std deviations");
    free_s_array(paths);
    free_s_array(paths_used);
    free_c_array(line_buffer);
    free_i_array(stat_indices);
    free_sample_sum_array(ss_array);
    free_d_array(means);
    free_d_array(std_devs);
    free_d_array(exp_means);
    free_d_array(exp_std_devs);
}
Beispiel #2
0
END_TEST

START_TEST (test_split_str_d) {
    int ret;
    d_array * v;
    d_array * exp;
    v = init_d_array(1);
    exp = init_d_array(1);
    char * string = "1.01\t0.009\t2.0e2";
    append_d_array(exp, 1.01);
    append_d_array(exp, 0.009);
    append_d_array(exp, 200.0);
    ret = split_str_d(string, v, 0);
    ck_assert_int_eq(ret, 0);
    ck_assert_int_eq(v->length, 3);
    ck_assert_msg((d_arrays_equal(v, exp, 0.000001) != 0),
            "unexpected result of `split_str_d`");
    ret = split_str_d(string, v, 3);
    ck_assert_int_eq(ret, 0);
    ret = split_str_d(string, v, 4);
    ck_assert_int_eq(ret, 3);
    ck_assert_msg((d_arrays_equal(v, exp, 0.000001) != 0),
            "unexpected result of `split_str_d`");
    free_d_array(v);
    free_d_array(exp);
}
Beispiel #3
0
END_TEST

START_TEST (test_reject_p2_n2_c4) {
    int i;
    s_array * paths;
    c_array * line_buffer;
    i_array * stat_indices;
    d_array * obs_stats;
    d_array * means;
    d_array * std_devs;
    s_array * header;
    sample_array * samples;
    int num_to_retain;
    num_to_retain = 2;
    paths = init_s_array(1);
    line_buffer = init_c_array(1023);
    stat_indices = init_i_array(4);
    means = init_d_array(1);
    std_devs = init_d_array(1);
    obs_stats = init_d_array(1);
    header = init_s_array(1);
    append_s_array(paths, "data/test_parameter_stat_samples4.txt");
    append_s_array(paths, "data/test_parameter_stat_samples.txt");
    parse_header(get_s_array(paths, 0), line_buffer, header);
    for (i = 2; i < header->length; i++) {
        append_i_array(stat_indices, i);
    }
    append_d_array(obs_stats, 0.1);
    append_d_array(obs_stats, 0.21);
    append_d_array(obs_stats, 1.0);
    append_d_array(obs_stats, 2.0);
    append_d_array(means, 0.25);
    append_d_array(means, 0.2225);
    append_d_array(means, 2.5);
    append_d_array(means, 3.0);
    append_d_array(std_devs, 0.1290994);
    append_d_array(std_devs, 0.009574271);
    append_d_array(std_devs, 1.290994);
    append_d_array(std_devs, 1.154701);
    standardize_vector(obs_stats, means, std_devs);
    samples = reject(paths, line_buffer, stat_indices, obs_stats, means,
            std_devs, num_to_retain, header);
    ck_assert_int_eq(samples->length, num_to_retain);
    ck_assert_int_eq(samples->capacity, num_to_retain);
    ck_assert_msg((almost_equal(samples->a[0]->distance, 0.0, 0.000001)),
            "euclidean distance was %lf, expected %lf",
            samples->a[0]->distance, 0.0);
    ck_assert_msg((almost_equal(samples->a[1]->distance, 0.130035, 0.000001)),
            "euclidean distance was %lf, expected %lf",
            samples->a[1]->distance, 0.130035);
    free_s_array(paths);
    free_c_array(line_buffer);
    free_i_array(stat_indices);
    free_d_array(obs_stats);
    free_sample_array(samples);
    free_d_array(means);
    free_d_array(std_devs);
    free_s_array(header);
}
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_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);
}
Beispiel #6
0
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);
}
END_TEST

START_TEST (test_frequency_of_int_partitions_by_k_n0) {
    int n, tp;
    d_array * probs;
    probs = init_d_array(1);
    n = 0;
    tp = frequency_of_int_partitions_by_k(n, probs); // SIGABRT
    free_d_array(probs);
}
Beispiel #8
0
END_TEST

START_TEST (test_set_d_array_fail) {
    int size;
    d_array * v;
    size = 1;
    v = init_d_array(size);
    append_d_array(v, 0.1);
    set_d_array(v, 1, 0.3); // SIGABRT
}
Beispiel #9
0
END_TEST

START_TEST (test_summarize_stat_samples_p1_n4_missing_cell) {
    int i;
    s_array * paths;
    s_array * paths_used;
    c_array * line_buffer;
    i_array * stat_indices;
    sample_sum_array * ss_array;
    d_array * means;
    d_array * std_devs;
    d_array * exp_means;
    d_array * exp_std_devs;
    int num_to_sample;
    int expected_num_cols;
    expected_num_cols = 6;
    num_to_sample = 4;
    paths = init_s_array(1);
    paths_used = init_s_array(1);
    line_buffer = init_c_array(1023);
    stat_indices = init_i_array(4);
    ss_array = init_sample_sum_array(4);
    means = init_d_array(1);
    std_devs = init_d_array(1);
    exp_means = init_d_array(1);
    exp_std_devs = init_d_array(1);
    append_s_array(paths, "data/test_parameter_stat_samples.missing_cell.txt");
    for (i = 2; i < expected_num_cols; i++) {
        append_i_array(stat_indices, i);
    }
    summarize_stat_samples(paths, line_buffer, stat_indices, ss_array, means,
            std_devs, num_to_sample, expected_num_cols, paths_used); // exit(1)
    free_s_array(paths);
    free_s_array(paths_used);
    free_c_array(line_buffer);
    free_i_array(stat_indices);
    free_sample_sum_array(ss_array);
    free_d_array(means);
    free_d_array(std_devs);
    free_d_array(exp_means);
    free_d_array(exp_std_devs);
}
Beispiel #10
0
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);
}
Beispiel #11
0
END_TEST

START_TEST (test_set_d_array) {
    int size;
    d_array * v;
    size = 1;
    v = init_d_array(size);
    append_d_array(v, 0.1);
    ck_assert_msg((v->a[0] == 0.1), "`d_array` element is %lf, expecting %lf",
            v->a[0], 0.1);
    set_d_array(v, 0, 0.2);
    ck_assert_msg((v->a[0] == 0.2), "`d_array` element is %lf, expecting %lf",
            v->a[0], 0.2);
}
Beispiel #12
0
END_TEST

START_TEST (test_d_arrays_equal) {
    int size, ret;
    d_array * v1;
    d_array * v2;
    double s = 1.0;
    double e = 0.0000001;
    size = 3;
    v1 = init_d_array(size);
    v2 = init_d_array(size);
    ret = d_arrays_equal(v1, v2, e);
    ck_assert_msg((ret != 0), "`d_array`s not equal, but should be");
    append_d_array(v1, s);
    ret = d_arrays_equal(v1, v2, e);
    ck_assert_msg((ret == 0), "`d_array`s equal, but should not be");
    append_d_array(v2, s);
    ret = d_arrays_equal(v1, v2, e);
    ck_assert_msg((ret != 0), "`d_array`s not equal, but should be");
    s = 2.0;
    append_d_array(v1, s);
    ret = d_arrays_equal(v1, v2, e);
    ck_assert_msg((ret == 0), "`d_array`s equal, but should not be");
    append_d_array(v2, s);
    ret = d_arrays_equal(v1, v2, e);
    ck_assert_msg((ret != 0), "`d_array`s not equal, but should be");
    append_d_array(v1, s);
    ret = d_arrays_equal(v1, v2, e);
    ck_assert_msg((ret == 0), "`d_array`s equal, but should not be");
    s = 3.0;
    append_d_array(v2, s);
    ret = d_arrays_equal(v1, v2, e);
    ck_assert_msg((ret == 0), "`d_array`s equal, but should not be");
    free_d_array(v1);
    free_d_array(v2);
}
Beispiel #13
0
END_TEST

START_TEST (test_expand_d_array) {
    int i, size;
    d_array * v;
    size = 1;
    v = init_d_array(size);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 0);
    for (i = 0; i < 5; i++) {
        expand_d_array(v);
        size *= 2;
        ck_assert_int_eq(v->capacity, size);
        ck_assert_int_eq(v->length, 0);
    }
    free_d_array(v);
}
Beispiel #14
0
END_TEST

START_TEST (test_append_d_array) {
    int size;
    d_array * v;
    size = 1;
    v = init_d_array(size);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 0);
    append_d_array(v, 0.1);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 1);
    ck_assert_msg((v->a[0] == 0.1), "`d_array` element is %lf, expecting %lf",
            v->a[0], 0.1);
    append_d_array(v, 1.9);
    ck_assert_int_eq(v->capacity, size*2);
    ck_assert_int_eq(v->length, 2);
    ck_assert_msg((v->a[1] == 1.9), "`d_array` element is %lf, expecting %lf",
            v->a[0], 1.9);
}
Beispiel #15
0
END_TEST

START_TEST (test_init_d_array_fail) {
    d_array * v;
    v = init_d_array(0); // SIGABRT
}