Ensure(find_first_mode_greater_than_or_equal_to, returns_correct_results_for_an_ordered_array) { create_an_ordered_array(); int i, index, max_value = ARRAY_LENGTH / NUM_OF_OCCURANCE; double value; value = modes_array[0].modulus; index = find_first_mode_greater_than_or_equal_to(value, modes_array, ARRAY_LENGTH); assert_that(index, is_equal_to(0)); for (i = NUM_OF_OCCURANCE; i < max_value; i += max_value / 20) { value = i / NUM_OF_OCCURANCE + .5; index = find_first_mode_greater_than_or_equal_to(value, modes_array, ARRAY_LENGTH); assert_true(modes_array[index + 1].modulus > value); assert_true(modes_array[index].modulus >= value); assert_true(modes_array[index - 1].modulus < value); } value = modes_array[ARRAY_LENGTH - 1].modulus + 1; index = find_first_mode_greater_than_or_equal_to(value, modes_array, ARRAY_LENGTH); assert_that(index, is_equal_to(NOT_FOUND)); }
Ensure(find_first_mode_greater_than_or_equal_to, returns_right_results_in_a_random_array) { fill_array_with_random_numbers(); int i, index, start_point = ARRAY_LENGTH; for (i = 1; i < ARRAY_LENGTH; i++) { if (modes_array[i - 1].modulus != modes_array[i].modulus) { start_point = i - 1; break; } } double value; value = modes_array[0].modulus; index = find_first_mode_greater_than_or_equal_to(value, modes_array, ARRAY_LENGTH); assert_that(index, is_equal_to(start_point)); for (i = start_point; i < ARRAY_LENGTH; i += ARRAY_LENGTH / 20) { value = floor(modes_array[i].modulus); index = find_first_mode_greater_than_or_equal_to(value, modes_array, ARRAY_LENGTH); assert_true(modes_array[index - 1].modulus <= value); assert_true(modes_array[index].modulus > value); assert_true(modes_array[index + 1].modulus > value); } value = modes_array[ARRAY_LENGTH - 1].modulus + 1; index = find_first_mode_greater_than_or_equal_to(value, modes_array, ARRAY_LENGTH); assert_that(index, is_equal_to(NOT_FOUND)); }
static void expect_debug_output(FILE *fp, const char *msg) { expect(mock_vfprintf, when(stream, is_equal_to(fp)), when(res_str, is_equal_to_string(msg))); expect(mock_fprintf, when(stream, is_equal_to(fp)), when(res_str, is_equal_to_string("\n"))); expect(mock_fflush, when(file, is_equal_to(fp))); }
Ensure(string, create_empty) { // Allocate an empty string struct zob_string * p_string = NULL; zob_string_create(&p_string); assert_that(p_string, is_not_equal_to(NULL)); size_t size = 0; zob_string_size_get(p_string, &size); assert_that(size, is_equal_to(0)); zob_string_dispose(&p_string); assert_that(p_string, is_equal_to(NULL)); }
Ensure(eclGetContextInteractively, commandQueueConsistentWithDevice) { size_t size; cl_device_id qDevice; err = eclGetContextInteractively(&ctx); assert_that(err, is_equal_to(CL_SUCCESS)); clGetCommandQueueInfo(ctx.queue, CL_QUEUE_DEVICE, 0, 0, &size); assert_that(err, is_equal_to(CL_SUCCESS)); assert_that(size, is_equal_to(sizeof(qDevice))); clGetCommandQueueInfo(ctx.queue, CL_QUEUE_DEVICE, size, &qDevice, 0); assert_that(qDevice, is_equal_to(ctx.device)); }
Ensure(eclGetContextInteractively, commandQueueConsistentWithContext) { size_t size; cl_context qCtx; err = eclGetContextInteractively(&ctx); assert_that(err, is_equal_to(CL_SUCCESS)); clGetCommandQueueInfo(ctx.queue, CL_QUEUE_CONTEXT, 0, 0, &size); assert_that(err, is_equal_to(CL_SUCCESS)); assert_that(size, is_equal_to(sizeof(qCtx))); clGetCommandQueueInfo(ctx.queue, CL_QUEUE_CONTEXT, size, &qCtx, 0); assert_that(qCtx, is_equal_to(ctx.context)); }
Ensure(generate_logarithmic_bins, sets_bins_boundries_correct) { generate_logarithmic_bins(&bins_vector, indexed_mode_modulus, &conf); bins_struct bin; while (bins_vector.log_length > 0) { vector_pop(&bins_vector, &bin); assert_that(bin.k_min, is_equal_to(pow(jump, 2 * bins_vector.log_length))); assert_that(bin.k, is_equal_to(pow(jump, 2 * bins_vector.log_length + 1))); assert_that(bin.k_max, is_equal_to(pow(jump, 2 * bins_vector.log_length + 2))); } }
Ensure(string, create_and_assign) { // Allocate an empty string and assign data struct zob_string * p_string = NULL; zob_string_create(&p_string); assert_that(p_string, is_not_equal_to(NULL)); char const * p_message = "Alea jacta est"; size_t size = 0; zob_string_write(p_string, size, p_message, &size); assert_that(strlen(p_message), is_equal_to(size)); zob_string_dispose(&p_string); assert_that(p_string, is_equal_to(NULL)); }
Ensure(Words, converts_spaces_to_zeroes) { char *sentence = strdup("Birds of a feather"); split_words(sentence); int comparison = memcmp("Birds\0of\0a\0feather", sentence, strlen(sentence)); assert_that(comparison, is_equal_to(0)); free(sentence); }
Ensure(load_save_matches, loads_matches_from_disk_properly) { vector **primatches = allocate(N_PRI_HALOS, sizeof(vector*)); vector **secmatches = allocate(N_SEC_HALOS, sizeof(vector*)); load_matches(MATCHES_FILE_ADDR, primatches, secmatches); int i, j; match *dummy_match = allocate(1, sizeof(*dummy_match)); for(i = 0; i < N_PRI_HALOS; i++) for(j = 0; j < i; j++){ dummy_match = vector_get(primatches[i], j); assert_that(dummy_match->matchid, is_equal_to(MATCHID)); assert_that_double(dummy_match->goodness, is_equal_to_double(GOODNESS)); } for(i = 0; i < N_PRI_HALOS; i++) free(primatches[i]); for(i = 0; i < N_SEC_HALOS; i++) free(secmatches[i]); free(primatches); free(secmatches); }
bool bigint_kernel_1:: operator == ( const bigint_kernel_1& rhs ) const { return is_equal_to(data,rhs.data); }
Ensure(eclGetContextInteractively, recoversFromBogusDeviceChoice) { eclSetDeviceChoice(mockInteractiveChoiceBogus); eclGetContextInteractively(&ctx); eclSetDeviceChoice(mockInteractiveChoice); err = eclGetContextInteractively(&ctx); assert_that(err, is_equal_to(CL_SUCCESS)); }
Ensure(vector_push, pushes_elements_to_vector_properly) { vector *double_v = new_vector(2, sizeof(double)); double dummy = 1.23456789; int i; for(i = 0; i < 4; i++) vector_push(double_v, &dummy); assert_that(double_v->elems, is_non_null); assert_that(double_v->allocLength, is_equal_to(4)); assert_that(double_v->logLength, is_equal_to(4)); dispose_vector(&double_v); }
Ensure(ByteStuffer, sends_three_byte_frame_data_in_the_middle) { uint8_t data[] = {0, 0x55, 0}; byte_stuffer_send_frame(0, data, 3); uint8_t expected[] = {1, 2, 0x55, 1, 0}; assert_that(sent_data_size, is_equal_to(sizeof(expected))); assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); }
Ensure(ByteStuffer, receives_two_long_frames_and_some_more) { uint8_t expected[515]; int i; int j; for (j=0;j<2;j++) { for (i=0;i<254;i++) { expected[i+254*j] = i + 1; } } for (i=0;i<7;i++) { expected[254*2+i] = i + 1; } expect(validator_recv_frame, when(size, is_equal_to(515)), when(data, is_equal_to_contents_of(expected, 510)) ); byte_stuffer_recv_byte(0, 0xFF); for (i=0;i<254;i++) { byte_stuffer_recv_byte(0, i+1); } byte_stuffer_recv_byte(0, 0xFF); for (i=0;i<254;i++) { byte_stuffer_recv_byte(0, i+1); } byte_stuffer_recv_byte(0, 8); byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 3); byte_stuffer_recv_byte(0, 4); byte_stuffer_recv_byte(0, 5); byte_stuffer_recv_byte(0, 6); byte_stuffer_recv_byte(0, 7); byte_stuffer_recv_byte(0, 0); }
Ensure(ByteStuffer, sends_three_byte_frame_with_all_zeroes) { uint8_t data[] = {0, 0, 0}; byte_stuffer_send_frame(0, data, 3); uint8_t expected[] = {1, 1, 1, 1, 0}; assert_that(sent_data_size, is_equal_to(sizeof(expected))); assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); }
Ensure(ByteStuffer, sends_two_byte_frame) { uint8_t data[] = {5, 0x77}; byte_stuffer_send_frame(0, data, 2); uint8_t expected[] = {3, 5, 0x77, 0}; assert_that(sent_data_size, is_equal_to(sizeof(expected))); assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); }
Ensure(ByteStuffer, sends_two_byte_frame_starting_with_non_zero) { uint8_t data[] = {9, 0}; byte_stuffer_send_frame(1, data, 2); uint8_t expected[] = {2, 9, 1, 0}; assert_that(sent_data_size, is_equal_to(sizeof(expected))); assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); }
Ensure(ByteStuffer, send_one_byte_frame) { uint8_t data[] = {5}; byte_stuffer_send_frame(1, data, 1); uint8_t expected[] = {2, 5, 0}; assert_that(sent_data_size, is_equal_to(sizeof(expected))); assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); }
Ensure(eclGetContextInteractively, returnsAValidContext) { eclGetContextInteractively(&ctx); if (ctx.context) { size_t size; err = clGetContextInfo(ctx.context, CL_CONTEXT_PROPERTIES, 0, 0, &size); assert_that(err, is_equal_to(CL_SUCCESS)); } }
Ensure(eclGetContextInteractively, returnsAValidDevice) { eclGetContextInteractively(&ctx); if (ctx.device) { size_t size; err = clGetDeviceInfo(ctx.device, CL_DEVICE_ENDIAN_LITTLE, 0, 0, &size); assert_that(err, is_equal_to(CL_SUCCESS)); } }
Ensure(eclGetContextInteractively, returnsAValidCommandQueue) { eclGetContextInteractively(&ctx); if (ctx.queue) { size_t size; err = clGetCommandQueueInfo(ctx.queue, CL_QUEUE_PROPERTIES, 0, 0, &size); assert_that(err, is_equal_to(CL_SUCCESS)); } }
Ensure(ByteStuffer, receives_two_valid_frames) { uint8_t expected1[] = {5, 0}; uint8_t expected2[] = {3}; expect(validator_recv_frame, when(size, is_equal_to(2)), when(data, is_equal_to_contents_of(expected1, 2)) ); expect(validator_recv_frame, when(size, is_equal_to(1)), when(data, is_equal_to_contents_of(expected2, 1)) ); byte_stuffer_recv_byte(1, 2); byte_stuffer_recv_byte(1, 5); byte_stuffer_recv_byte(1, 1); byte_stuffer_recv_byte(1, 0); byte_stuffer_recv_byte(1, 2); byte_stuffer_recv_byte(1, 3); byte_stuffer_recv_byte(1, 0); }
Ensure(ByteStuffer, receives_single_zero_valid_frame) { uint8_t expected[] = {0}; expect(validator_recv_frame, when(size, is_equal_to(1)), when(data, is_equal_to_contents_of(expected, 1)) ); byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 0); }
Ensure(FFT, can_be_constructed_from_DMDA) { ierr = DMDACreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,20,2,1,NULL,&da); CHKERRV(ierr); ierr = scFftCreate(da, &fft); assert_that(ierr, is_equal_to(0)); scFftDestroy(&fft); CHKERRV(ierr); ierr = DMDestroy(&da); CHKERRV(ierr); }
Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) { uint8_t original_data[] = { 1, 0, 3, 0, 0, 9}; byte_stuffer_send_frame(1, original_data, sizeof(original_data)); expect(validator_recv_frame, when(size, is_equal_to(sizeof(original_data))), when(data, is_equal_to_contents_of(original_data, sizeof(original_data))) ); int i; for(i=0;i<sent_data_size;i++) { byte_stuffer_recv_byte(0, sent_data[i]); } }
Ensure(ByteStuffer, receives_three_bytes_valid_frame) { uint8_t expected[] = {0x37, 0x99, 0xFF}; expect(validator_recv_frame, when(size, is_equal_to(3)), when(data, is_equal_to_contents_of(expected, 3)) ); byte_stuffer_recv_byte(0, 4); byte_stuffer_recv_byte(0, 0x37); byte_stuffer_recv_byte(0, 0x99); byte_stuffer_recv_byte(0, 0xFF); byte_stuffer_recv_byte(0, 0); }
Ensure(string, create_and_assign_then_look_for_char) { // Allocate an empty string, assign data and search for a character struct zob_string * p_string = NULL; zob_string_create(&p_string); assert_that(p_string, is_not_equal_to(NULL)); char const * p_message = "Alea jacta est"; size_t size = 0; zob_string_write(p_string, size, p_message, &size); assert_that(strlen(p_message), is_equal_to(size)); size_t position = 0; bool has_found = false; zob_string_find_char(p_string, 'j', 0, size, &position, &has_found); assert_that(has_found, is_true); assert_that(position, is_equal_to(5)); zob_string_dispose(&p_string); assert_that(p_string, is_equal_to(NULL)); }
Ensure(ByteStuffer, receives_valid_frame_with_zeroes) { uint8_t expected[] = {5, 0, 3, 0}; expect(validator_recv_frame, when(size, is_equal_to(4)), when(data, is_equal_to_contents_of(expected, 4)) ); byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 5); byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 3); byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 0); }
Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) { uint8_t expected[MAX_FRAME_SIZE] = {}; expect(validator_recv_frame, when(size, is_equal_to(MAX_FRAME_SIZE)), when(data, is_equal_to_contents_of(expected, MAX_FRAME_SIZE)) ); int i; byte_stuffer_recv_byte(0, 1); for(i=0;i<MAX_FRAME_SIZE;i++) { byte_stuffer_recv_byte(0, 1); } byte_stuffer_recv_byte(0, 0); }