Skip to content

Commit

Permalink
Merge pull request #29 from jeromekelleher/more-level-tests
Browse files Browse the repository at this point in the history
Some testing
  • Loading branch information
jeromekelleher authored Jul 16, 2024
2 parents 3f6c405 + 020c2fd commit 12691b2
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 217 deletions.
10 changes: 7 additions & 3 deletions lib/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ validate_encoder(
for (buflen = 0; buflen < min_len; buflen++) {
buf = malloc((size_t) buflen);
CU_ASSERT_FATAL(buf != NULL);
ret = vcz_variant_encoder_write_row(encoder, j, buf, (size_t) buflen);
ret = vcz_variant_encoder_encode(encoder, j, buf, (size_t) buflen);
free(buf);
CU_ASSERT_FATAL(ret == VCZ_ERR_BUFFER_OVERFLOW);
}
buflen = min_len;
buf = malloc((size_t) buflen);
CU_ASSERT_FATAL(buf != NULL);
ret = vcz_variant_encoder_write_row(encoder, j, buf, (size_t) buflen);
ret = vcz_variant_encoder_encode(encoder, j, buf, (size_t) buflen);
/* printf("ret = %d\n", (int) ret); */
/* printf("GOT:'%s'\n", buf); */
/* printf("EXP:'%s'\n", expected[j]); */
Expand All @@ -82,6 +82,10 @@ validate_encoder(
CU_ASSERT_NSTRING_EQUAL_FATAL(buf, expected[j], ret);
free(buf);
}
for (j = num_rows; j < num_rows + 5; j++) {
ret = vcz_variant_encoder_encode(encoder, j, buf, 0);
CU_ASSERT_EQUAL_FATAL(ret, VCZ_ERR_VARIANT_OUT_OF_BOUNDS);
}
}

static void
Expand Down Expand Up @@ -294,7 +298,7 @@ static void
test_float_field_2d(void)
{
// clang-format off
int32_t data[] = {
int32_t data[] = {
VCZ_FLOAT32_MISSING_AS_INT32, VCZ_FLOAT32_MISSING_AS_INT32, VCZ_FLOAT32_MISSING_AS_INT32,
VCZ_FLOAT32_MISSING_AS_INT32, VCZ_FLOAT32_MISSING_AS_INT32, VCZ_FLOAT32_FILL_AS_INT32,
VCZ_FLOAT32_MISSING_AS_INT32, VCZ_FLOAT32_FILL_AS_INT32, VCZ_FLOAT32_FILL_AS_INT32,
Expand Down
23 changes: 14 additions & 9 deletions lib/vcf_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ vcz_variant_encoder_write_info_fields(const vcz_variant_encoder_t *self, size_t
if (self->num_info_fields > 0) {
missing = malloc(self->num_info_fields * sizeof(*missing));
if (missing == NULL) {
offset = VCZ_ERR_NO_MEMORY;
goto out;
offset = VCZ_ERR_NO_MEMORY; // GCOVR_EXCL_LINE
goto out; // GCOVR_EXCL_LINE
}
for (j = 0; j < self->num_info_fields; j++) {
missing[j] = vcz_field_is_missing_1d(&self->info_fields[j], variant);
Expand Down Expand Up @@ -648,8 +648,8 @@ vcz_variant_encoder_write_format_fields(const vcz_variant_encoder_t *self,
if (self->num_format_fields > 0) {
missing = malloc(self->num_format_fields * sizeof(*missing));
if (missing == NULL) {
offset = VCZ_ERR_NO_MEMORY;
goto out;
offset = VCZ_ERR_NO_MEMORY; // GCOVR_EXCL_LINE
goto out; // GCOVR_EXCL_LINE
}
for (j = 0; j < self->num_format_fields; j++) {
missing[j]
Expand Down Expand Up @@ -775,12 +775,17 @@ vcz_variant_encoder_write_filter(const vcz_variant_encoder_t *self, size_t varia
}

int64_t
vcz_variant_encoder_write_row(
vcz_variant_encoder_encode(
const vcz_variant_encoder_t *self, size_t variant, char *buf, size_t buflen)
{
int64_t offset = 0;
size_t j;

if (variant >= self->num_variants) {
offset = VCZ_ERR_VARIANT_OUT_OF_BOUNDS;
goto out;
}

for (j = 0; j < VCZ_NUM_FIXED_FIELDS; j++) {
if (vcz_field_is_missing_1d(&self->fixed_fields[j], variant)) {
offset = append_char(buf, '.', offset, (int64_t) buflen);
Expand Down Expand Up @@ -858,8 +863,8 @@ vcz_variant_encoder_add_info_field(vcz_variant_encoder_t *self, const char *name
tmp = realloc(
self->info_fields, self->max_info_fields * sizeof(*self->info_fields));
if (tmp == NULL) {
ret = VCZ_ERR_NO_MEMORY;
goto out;
ret = VCZ_ERR_NO_MEMORY; // GCOVR_EXCL_LINE
goto out; // GCOVR_EXCL_LINE
}
self->info_fields = tmp;
}
Expand All @@ -886,8 +891,8 @@ vcz_variant_encoder_add_format_field(vcz_variant_encoder_t *self, const char *na
tmp = realloc(
self->format_fields, self->max_format_fields * sizeof(*self->format_fields));
if (tmp == NULL) {
ret = VCZ_ERR_NO_MEMORY;
goto out;
ret = VCZ_ERR_NO_MEMORY; // GCOVR_EXCL_LINE
goto out; // GCOVR_EXCL_LINE
}
self->format_fields = tmp;
}
Expand Down
18 changes: 2 additions & 16 deletions lib/vcf_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#define VCZ_ERR_NO_MEMORY (-100)
#define VCZ_ERR_BUFFER_OVERFLOW (-101)
#define VCZ_ERR_VARIANT_OUT_OF_BOUNDS (-102)

/* Built-in-limitations */
#define VCZ_ERR_FIELD_NAME_TOO_LONG (-201)
Expand Down Expand Up @@ -77,21 +78,6 @@ typedef struct {
vcz_field_t *format_fields;
} vcz_variant_encoder_t;

/* // clang-format off */
/* int vcz_variant_encoder_init(vcz_variant_encoder_t *self, */
/* size_t num_variants, size_t num_samples, */
/* const char *contig_data, size_t contig_item_size, */
/* const int32_t *position_data, */
/* const char *id_data, size_t id_item_size, size_t id_num_columns, */
/* const char *ref_data, size_t ref_item_size, */
/* const char *alt_data, size_t alt_item_size, size_t alt_num_columns, */
/* const float *qual_data, */
/* const char *filter_id_data, size_t filter_id_item_size, size_t
* filter_id_num_columns, */
/* const int8_t *filter_data */
/* ); */
/* // clang-format on */

int vcz_variant_encoder_init(
vcz_variant_encoder_t *self, size_t num_variants, size_t num_samples);
void vcz_variant_encoder_free(vcz_variant_encoder_t *self);
Expand All @@ -117,7 +103,7 @@ int vcz_variant_encoder_add_info_field(vcz_variant_encoder_t *self, const char *
int vcz_variant_encoder_add_format_field(vcz_variant_encoder_t *self, const char *name,
int type, size_t item_size, size_t num_columns, const void *data);

int64_t vcz_variant_encoder_write_row(
int64_t vcz_variant_encoder_encode(
const vcz_variant_encoder_t *self, size_t row, char *buf, size_t buflen);

int vcz_itoa(char *buf, int64_t v);
Expand Down
Loading

0 comments on commit 12691b2

Please sign in to comment.