-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced unit tests using GoogleTest framework.
So far only two test suites implemented.
- Loading branch information
1 parent
8d44316
commit a00fadb
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
include ../../common.mk | ||
AINC = ../../include | ||
CXX = g++ | ||
CXXFLAGS := -std=c++11 -Wall -pedantic -pthread ${CXXFLAGS} | ||
LDFLAGS = -L../googletest -lgtest -lgtest_main | ||
INCLS += -I$(AINC) -isystem ../googletest/include/ | ||
|
||
# Link all tests to a single test binary | ||
unittests: lldouble_unittest.o fasta_unittest.o | ||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(INCLS) lldouble_unittest.o fasta_unittest.o ../lldouble.o ../fasta.o -o unittests | ||
|
||
# Here follows each individual Unit Test | ||
lldouble_unittest.o: lldouble_unittest.cc $(AINC)/lldouble.hh | ||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(INCLS) -c lldouble_unittest.cc | ||
|
||
fasta_unittest.o: fasta_unittest.cc $(AINC)/fasta.hh | ||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $(INCLS) -c fasta_unittest.cc | ||
|
||
# execute all tests: run test binary | ||
test: unittests | ||
./unittests | ||
|
||
clean: | ||
rm -f *.o unittests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* fasta_unittest.cc | ||
* | ||
* License: Artistic License, see file LICENSE.TXT or | ||
* https://opensource.org/licenses/artistic-license-1.0 | ||
* | ||
* Description: Unit tests for FASTA input | ||
*/ | ||
|
||
#include "fasta.hh" | ||
#include "gtest/gtest.h" | ||
|
||
#include <fstream> | ||
#include <string> | ||
|
||
namespace { | ||
TEST(FastaTest, ReadFile) { | ||
char *sequence = NULL, *name = NULL; | ||
int length; | ||
std::ifstream ifstrm("test.fa"); | ||
if (!ifstrm){ | ||
FAIL() << "Could not read unittests/test.fa file."; | ||
} else { | ||
readOneFastaSeq(ifstrm, sequence, name, length); | ||
ASSERT_EQ(length, 34); | ||
ASSERT_STREQ(name, "aVeryNiceGeneName"); | ||
ASSERT_STREQ(sequence, "atttgtttgtttgtttgctttgtttgttttgttt"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* lldouble_unittest.cc | ||
* | ||
* License: Artistic License, see file LICENSE.TXT or | ||
* https://opensource.org/licenses/artistic-license-1.0 | ||
* | ||
* Description: Unit tests for LLDouble | ||
*/ | ||
|
||
#include "lldouble.hh" | ||
#include "gtest/gtest.h" | ||
|
||
namespace { | ||
TEST(LLDoubleTest, Summation) { // 1+3 = 4 | ||
long double a=1.0, b=3.0, s=a+b; | ||
LLDouble lda(a), ldb(b); | ||
LLDouble lds = lda + ldb; | ||
EXPECT_DOUBLE_EQ(s, lds.doubleValue()); | ||
} | ||
TEST(LLDoubleTest, SimpleMultiplication) { // 2*3=6 | ||
EXPECT_DOUBLE_EQ(6.0, (LLDouble(2.0) * LLDouble(3.0)).doubleValue()); | ||
} | ||
TEST(LLDoubleTest, ChainMultiplication) { | ||
// multiply by a many small factors and then divide by the same factors | ||
// tests implicitly testPrecision | ||
unsigned i, n=10000; | ||
double* factors = new double[n]; | ||
for (unsigned i = 0; i<n; ++i){ | ||
factors[i] = (i+10000.0) / 45678.9; | ||
} | ||
LLDouble p(1.0); | ||
for (i = 0; i<n; ++i){ | ||
p *= factors[i]; | ||
} | ||
for (i = 0; i<n; ++i){ | ||
p /= factors[i]; | ||
} | ||
EXPECT_NEAR(1.0, p.doubleValue(), 1e-8); | ||
delete [] factors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
>aVeryNiceGeneName | ||
atttgtttgtttgtttgctttgtttgt | ||
tttgttt |