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); }
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_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); }