END_TEST /** * `c_array` tests */ START_TEST (test_init_free_c_array) { int i, size; c_array * v; size = 10; v = init_c_array(size); ck_assert_int_eq(v->capacity, size); ck_assert_msg((sizeof(v->capacity) == sizeof(int)), "`c_array.capacity` " "attribute is not an int"); ck_assert_msg((sizeof(v->a) == sizeof(long)), "Array attribute " "of `c_array` is not a pointer"); ck_assert_msg((sizeof(*v->a) == sizeof(char)), "Pointer to array" "of `c_array` is not pointing to char"); for (i = 0; i < v->capacity; i++) { ck_assert_msg((v->a[i] == 0), "Element %d of %d was not initialized " "to zero", i, size); } ck_assert_msg((v->a[v->capacity] == '\0'), "`c_array` does not have " "extra NULL terminating character"); free_c_array(v); }
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); }
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_get_c_array) { int size; c_array * v; char * s = "blah"; size = 1; v = init_c_array(size); assign_c_array(v, s); ck_assert_msg((*(get_c_array(v)) == *s), "`c_array` is %s, expecting %s", get_c_array(v), s); free_c_array(v); }
END_TEST START_TEST (test_expand_c_array) { int i, size; c_array * v; size = 7; v = init_c_array(size); ck_assert_int_eq(v->capacity, size); for (i = 0; i < 3; i++) { expand_c_array(v); size = ((size + 1) * 2) - 1; ck_assert_int_eq(v->capacity, size); ck_assert_msg((v->a[v->capacity] == '\0'), "`c_array` does not " "have extra NULL terminating character"); } free_c_array(v); }
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); }
END_TEST START_TEST (test_assign_c_array) { int size; c_array * v; char * s = "blah"; size = 1; v = init_c_array(size); assign_c_array(v, s); ck_assert_int_eq(v->capacity, 7); ck_assert_msg((v->a[8] == '\0'), "`c_array` does not have " "extra NULL terminating character"); ck_assert_msg((v->a[5] == '\0'), "`c_array` did not copy " "extra NULL terminating character of target"); ck_assert_msg((v->a[0] == 'b'), "`c_array` element is %c, expecting %c", v->a[0], 'b'); ck_assert_msg((v->a[1] == 'l'), "`c_array` element is %c, expecting %c", v->a[1], 'l'); ck_assert_msg((v->a[2] == 'a'), "`c_array` element is %c, expecting %c", v->a[2], 'a'); ck_assert_msg((v->a[3] == 'h'), "`c_array` element is %c, expecting %c", v->a[3], 'h'); free_c_array(v); }
END_TEST START_TEST (test_init_c_array_fail) { c_array * v; v = init_c_array(0); // SIGABRT }