From b63a56e30184a277e4c62dbb9533a61d4324ca3c Mon Sep 17 00:00:00 2001 From: benney Date: Wed, 18 Dec 2024 10:41:22 +1100 Subject: [PATCH 1/2] add tests for fastqreader --- CMakeLists.txt | 5 +++++ test/config.h.in | 7 +++++++ test/fastqreader_test.cpp | 44 ++++++++++++++++++++++++--------------- testdata/R1.fq | 36 ++++++++++++++++++++++++++++++++ testdata/R2.fq | 36 ++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 test/config.h.in create mode 100644 testdata/R1.fq create mode 100644 testdata/R2.fq diff --git a/CMakeLists.txt b/CMakeLists.txt index 3292af9..02b2407 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,12 @@ target_link_libraries( # tests target enable_testing() find_package(GTest CONFIG REQUIRED) +configure_file(test/config.h.in ${CMAKE_BINARY_DIR}/include/config.h) add_executable(fastplong_tests ${FASTPLONG_TEST_SOURCES}) +target_include_directories( + fastplong_tests + PRIVATE ${CMAKE_BINARY_DIR}/include +) target_link_libraries( fastplong_tests PRIVATE ${FASTPLONG_LIBS} diff --git a/test/config.h.in b/test/config.h.in new file mode 100644 index 0000000..2849009 --- /dev/null +++ b/test/config.h.in @@ -0,0 +1,7 @@ +// this file is necessary to help resolve the correct path when loading test data files. +// When tests using the IDE and CLI the working directory can be different. +// This substitute builds the absolute path to eliminate the need to depend on the working directory. +#pragma once + +#define FP_TESTDATA_R1 "${CMAKE_SOURCE_DIR}/testdata/R1.fq" +#define FP_TESTDATA_R2 "${CMAKE_SOURCE_DIR}/testdata/R2.fq" \ No newline at end of file diff --git a/test/fastqreader_test.cpp b/test/fastqreader_test.cpp index e71d027..1f62c53 100644 --- a/test/fastqreader_test.cpp +++ b/test/fastqreader_test.cpp @@ -1,22 +1,32 @@ #include #include "../src/fastqreader.h" -TEST(fastqreader, test) { - /*FastqReader reader1("testdata/R1.fq"); - FastqReader reader2("testdata/R1.fq"); - Read* r1 = NULL; - Read* r2 = NULL; - int i=0; - while(true){ - i++; - r1=reader1.read(); - r2=reader2.read(); - if(r1 == NULL || r2==NULL) +#include "config.h" +#include + +TEST(fastqreader, test) +{ + FastqReader reader1(FP_TESTDATA_R1); + + Read *r1 = NULL; + + std::vector v; + while (true) + { + r1 = reader1.read(); + if (r1 == nullptr) { break; - r1->print(); - r2->print(); - delete r1; - delete r2; - }*/ -} + } + v.push_back(r1); + } + EXPECT_EQ(v.size(), 9); + EXPECT_EQ(*v[0]->mName, "@AS500713:64:HFKJJBGXY:1:11101:1675:1101 1:A:0:TATAGCCT+GACCCCCA"); + EXPECT_EQ(*v[0]->mSeq, ""); + EXPECT_EQ(*v[0]->mStrand, "+"); + EXPECT_EQ(*v[0]->mQuality, ""); + EXPECT_EQ(*v[1]->mName, "@AS500713:64:HFKJJBGXY:1:11101:17113:1101 1:A:0:TATAGCCT+GTTTCTTA"); + EXPECT_EQ(*v[1]->mSeq, "TACAAAATGCACATCGCTGAAAGGGGTAAAGGAGAGAAATCGCTTTATAAAACCTTGAAAAGGAATATTCAAATATAAGCTGGGAAGGTATAAAAAACTCTGTACATCACAAGTAAACAAATGGAACCTGCAAAATATTAAACAAAGGATT"); + EXPECT_EQ(*v[1]->mStrand, "+"); + EXPECT_EQ(*v[1]->mQuality, "AAAAAEEEEE6EEAAAEEEEE6EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEEAEEEEEEEEEEEEEEEEECFE####EEEE6EE Date: Wed, 18 Dec 2024 11:13:45 +1100 Subject: [PATCH 2/2] add tests for stats --- CMakeLists.txt | 1 + test/stats_test.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/stats_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 02b2407..920b340 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,7 @@ set( test/globals.cpp test/polyx_test.cpp test/sequence_test.cpp + test/stats_test.cpp ) include_directories( # intel mac install location diff --git a/test/stats_test.cpp b/test/stats_test.cpp new file mode 100644 index 0000000..0359391 --- /dev/null +++ b/test/stats_test.cpp @@ -0,0 +1,23 @@ +#include +#include "../src/stats.h" +#include "../src/evaluator.h" +#include + +TEST(StatsTests, summarise) { + Read* left = new Read( + new string("@NS500713:64:HFKJJBGXY:1:11101:20469:1097 1:N:0:TATAGCCT+GGTCCCGA"), + new string("TTTTTTCTCTTGGACTCTAACACTGTTTTTTCTTATGAAAACACAGGAGTGATGACTAGTTGAGTGCATTCTTATGAGACTCATAGTCATTCTATGATGTAG"), + new string("+"), + new string("AAAAA6EEEEEEEEEEEEEEEEE#EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE")); + + Options* options = new Options(); + Stats stats(options); + stats.statRead(left); + stats.summarize(); + EXPECT_EQ(stats.getCycles(), 102); + EXPECT_EQ(stats.getBases(), 102); + EXPECT_EQ(stats.getReads(), 1); + EXPECT_EQ(stats.getQ20(), 101); + EXPECT_EQ(stats.getQ30(), 100); + EXPECT_EQ(stats.getGCNumber(), 35); +} \ No newline at end of file