Beispiel #1
0
END_TEST

START_TEST (test_split_str) {
    int ret;
    s_array * words;
    s_array * exp;
    words = init_s_array(1);
    exp = init_s_array(1);
    char * string = "one.1\ttwo.2\tthree.3\0";
    append_s_array(exp, "one.1");
    append_s_array(exp, "two.2");
    append_s_array(exp, "three.3");
    ret = split_str(string, words, 3);
    ck_assert_int_eq(ret, 0);
    ck_assert_int_eq(words->length, 3);
    ck_assert_msg((s_arrays_equal(words, exp) != 0),
            "unexpected result of `split_str`");
    ret = split_str(string, words, 3);
    ck_assert_int_eq(ret, 0);
    ret = split_str(string, words, 4);
    ck_assert_int_eq(ret, 3);
    ck_assert_msg((s_arrays_equal(words, exp) != 0),
            "unexpected result of `split_str`");
    free_s_array(words);
    free_s_array(exp);
}
Beispiel #2
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 #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);
}
Beispiel #4
0
END_TEST

START_TEST (test_get_s_array) {
    int size;
    s_array * v;
    char * s = "foo";
    char * s2 = "bar";
    size = 1;
    v = init_s_array(size);
    append_s_array(v, s);
    ck_assert_msg((*(get_s_array(v, 0)) == *s), "`s_array` element is %s, "
            "expecting %s", get_s_array(v, 0), s);
    append_s_array(v, s2);
    ck_assert_msg((*(get_s_array(v, 1)) == *s2), "`s_array` element is %s, "
            "expecting %s", get_s_array(v, 1), s2);
}
Beispiel #5
0
END_TEST

START_TEST (test_get_matching_indices) {
    s_array * search_strings;
    s_array * target_strings;
    i_array * indices;
    search_strings = init_s_array(1);
    target_strings = init_s_array(1);
    indices = init_i_array(1);
    append_s_array(search_strings, "foo");
    append_s_array(search_strings, "bar");
    append_s_array(target_strings, "boo");
    append_s_array(target_strings, "foo");
    append_s_array(target_strings, "bar");
    get_matching_indices(search_strings, target_strings, indices);
    ck_assert_int_eq(indices->length, 2);
    ck_assert_int_eq(indices->capacity, 2);
    ck_assert_int_eq(get_i_array(indices, 0), 1);
    ck_assert_int_eq(get_i_array(indices, 1), 2);
}
Beispiel #6
0
END_TEST

START_TEST (test_get_s_array_fail) {
    int size;
    s_array * v;
    char * s = "foo";
    size = 1;
    v = init_s_array(size);
    append_s_array(v, s);
    get_s_array(v, 1); // SIGABRT
}
Beispiel #7
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);
}
Beispiel #8
0
END_TEST

START_TEST (test_s_arrays_equal) {
    int size, ret;
    s_array * v1;
    s_array * v2;
    char * s = "foo";
    size = 3;
    v1 = init_s_array(size);
    v2 = init_s_array(size);
    ret = s_arrays_equal(v1, v2);
    ck_assert_msg((ret != 0), "`s_array`s not equal, but should be");
    append_s_array(v1, s);
    ret = s_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`s_array`s equal, but should not be");
    append_s_array(v2, s);
    ret = s_arrays_equal(v1, v2);
    ck_assert_msg((ret != 0), "`s_array`s not equal, but should be");
    s = "bar";
    append_s_array(v1, s);
    ret = s_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`s_array`s equal, but should not be");
    append_s_array(v2, s);
    ret = s_arrays_equal(v1, v2);
    ck_assert_msg((ret != 0), "`s_array`s not equal, but should be");
    append_s_array(v1, s);
    ret = s_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`s_array`s equal, but should not be");
    s = "blah";
    append_s_array(v2, s);
    ret = s_arrays_equal(v1, v2);
    ck_assert_msg((ret == 0), "`s_array`s equal, but should not be");
    free_s_array(v1);
    free_s_array(v2);
}
Beispiel #9
0
END_TEST

START_TEST (test_append_s_array) {
    int size;
    s_array * v;
    char * s = "foo";
    char * s2 = "bar";
    size = 1;
    v = init_s_array(size);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 0);
    append_s_array(v, s);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 1);
    ck_assert_msg((*v->a[0]->a == *s), "`s_array` element is %s, expecting %s",
            v->a[0]->a, s);
    append_s_array(v, s2);
    ck_assert_int_eq(v->capacity, size*2);
    ck_assert_int_eq(v->length, 2);
    ck_assert_msg((*v->a[1]->a == *s2), "`s_array` element is %s, expecting %s",
            v->a[0]->a, s2);
}
Beispiel #10
0
END_TEST

START_TEST (test_set_s_array) {
    int size;
    s_array * v;
    char * s = "foo";
    char * s2 = "bar";
    size = 1;
    v = init_s_array(size);
    append_s_array(v, s);
    ck_assert_msg((*v->a[0]->a == *s), "`s_array` element is %s, expecting %s",
            v->a[0], s);
    set_s_array(v, 0, s2);
    ck_assert_msg((*v->a[0]->a == *s2), "`s_array` element is %d, expecting %d",
            v->a[0], s2);
}
Beispiel #11
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 #12
0
END_TEST

START_TEST (test_get_matching_indices_fail) {
    s_array * search_strings;
    s_array * target_strings;
    i_array * indices;
    search_strings = init_s_array(1);
    target_strings = init_s_array(1);
    indices = init_i_array(1);
    append_s_array(search_strings, "foo");
    append_s_array(search_strings, "bar");
    append_s_array(target_strings, "boo");
    append_s_array(target_strings, "foo");
    append_s_array(target_strings, "bar");
    append_s_array(search_strings, "fail");
    get_matching_indices(search_strings, target_strings, indices); // exit(1)
}