Skip to content

Commit

Permalink
fix old func name, make test agree on where null terminators are
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawwave committed Mar 16, 2024
1 parent cc8a153 commit befe37f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/FastaVector.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ void fastaVectorGetHeader(const struct FastaVector *const fastaVector,
const size_t headerEndPosition =
fastaVector->metadata.data[headerIndex].headerEndPosition;

*headerLength = headerEndPosition - headerStartPosition;
// the -1 removes the terminator
*headerLength = headerEndPosition - headerStartPosition - 1;
*headerPtr = &fastaVector->header.charData[headerStartPosition];
}
}
Expand Down
5 changes: 2 additions & 3 deletions tests/fileReadTest/fileReadTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void readTest(char **const testHeaderStrings, char **const testSequenceStrings,
"fail on reading test1.fasta for test 1");

for (size_t i = 0; i < numHeaders; i++) {
// add 1 to the strings for the null terminators
const size_t expectedHeaderLength = strlen(testHeaderStrings[i]) + 1;
const size_t expectedHeaderLength = strlen(testHeaderStrings[i]);
const size_t expectedSequenceLength = strlen(testSequenceStrings[i]);
size_t headerLength;
char *headerPtr;
Expand Down Expand Up @@ -51,7 +50,7 @@ void readTest(char **const testHeaderStrings, char **const testSequenceStrings,
testSequenceStrings[i], (int)sequenceLength, sequencePtr);
testAssertString(stringsMatch, buffer);

char terminator = headerPtr[headerLength - 1];
char terminator = headerPtr[headerLength];
sprintf(buffer,
"header index %zu was not null terminated! (found char %u after "
"the end of the header)",
Expand Down
4 changes: 2 additions & 2 deletions tests/multiSequenceTest/multiSequenceTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ int main() {
for (uint8_t i = 0; i < 6; i++) {
size_t length;
char *charPtr;
fastaVectorFastaGetHeader(&fastaVector, i, &charPtr, &length);
fastaVectorGetHeader(&fastaVector, i, &charPtr, &length);
testAssertString(length == strlen(headers[i]),
"header lengths did not match");
testAssertString(strcmp(headers[i], charPtr) == 0,
"headers did not match exactly.");
fastaVectorFastaGetSequence(&fastaVector, i, &charPtr, &length);
fastaVectorGetSequence(&fastaVector, i, &charPtr, &length);
testAssertString(length == strlen(seqs[i]),
"sequence lengths did not match");
testAssertString(strcmp(seqs[i], charPtr) == 0,
Expand Down

0 comments on commit befe37f

Please sign in to comment.