Exemple #1
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);
}
Exemple #2
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);
}
Exemple #3
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);
}
Exemple #4
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);
}
Exemple #5
0
END_TEST

/**
 * `s_array` tests
 */
START_TEST (test_init_free_s_array) {
    int i, size;
    s_array * v;
    size = 10;
    v = init_s_array(size);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 0);
    ck_assert_msg((sizeof(v->length) == sizeof(int)), "`s_array.length` "
            "attribute is not an int");
    ck_assert_msg((sizeof(v->capacity) == sizeof(int)), "`s_array.capacity` "
            "attribute is not an int");
    ck_assert_msg((sizeof(v->a) == sizeof(long)), "Array attribute "
            "of `s_array` is not a pointer");
    ck_assert_msg((sizeof(*v->a) == sizeof(c_array *)), "Pointer to array"
            "of `s_array` is not pointing to array of `c_array`s");
    for (i = 0; i < v->capacity; i++) {
        ck_assert_msg((v->a[i]->capacity > 0), "`c_array` element %d of %d was "
                "not initialized ", i, size);
    }
    free_s_array(v);
}
Exemple #6
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);
}
Exemple #7
0
END_TEST

START_TEST (test_expand_s_array) {
    int i, size;
    s_array * v;
    size = 1;
    v = init_s_array(size);
    ck_assert_int_eq(v->capacity, size);
    ck_assert_int_eq(v->length, 0);
    for (i = 0; i < 5; i++) {
        expand_s_array(v);
        size *= 2;
        ck_assert_int_eq(v->capacity, size);
        ck_assert_int_eq(v->length, 0);
    }
    for (i = 0; i < v->capacity; i++) {
        ck_assert_msg((v->a[i]->capacity > 0), "`c_array` element %d of %d was "
                "not initialized ", i, size);
    }
    free_s_array(v);
}