Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature test peeling #81

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ SET_TESTS_PROPERTIES(build_gitkeep PROPERTIES
PASS_REGULAR_EXPRESSION "d41d8cd98f00b204e9800998ecf8427e"
)



################################################################################
# Compile unit tests
include_directories(../src/include)


# Make a test for each unit test file located in test/ dir
file(GLOB_RECURSE TESTS test_*[cc|cpp])
foreach(test ${TESTS})
Expand All @@ -49,6 +52,40 @@ foreach(test ${TESTS})
endforeach(test)

################################################################################



################################################################################
# temp Compile unit tests with *.cc
# TODO: Use a different filename pattern for now (test2_* instead of test_*).
# TODO: How to add min *.cc files instead of all *.cc later?
include_directories(./)

file(GLOB_RECURSE TESTS2 "test2_*[cc|cpp]")
foreach(test ${TESTS2})
get_filename_component(testName ${test} NAME_WE)
add_executable(${testName} EXCLUDE_FROM_ALL ${test}
${CMAKE_SOURCE_DIR}/src/lib/peeling.cc
## ../src/lib/likelihood.cc ../src/lib/newick.cc ../src/lib/pedigree.cc
## ../src/lib/mutation.cc ../src/lib/stats.cc
)
target_link_libraries(${testName}
Threads::Threads
Boost::PROGRAM_OPTIONS
Boost::FILESYSTEM
Boost::SYSTEM
Boost::UNIT_TEST_FRAMEWORK
EIGEN3::EIGEN3
HTSLIB::HTSLIB
)
add_test(${testName}_build "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${testName})
add_test(${testName}_run ${testName})
set_tests_properties(${testName}_run PROPERTIES DEPENDS ${testName}_build)
endforeach(test)

################################################################################


# Full executable tests

# Check if using download source package or running latest code inside a git repository
Expand Down
65 changes: 65 additions & 0 deletions test/boost_test_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Created by steven on 1/15/16.
//
// Replace some with with BOOST later
//

#ifndef DENOVOGEAR_BOOST_TEST_HELPER_H
#define DENOVOGEAR_BOOST_TEST_HELPER_H

#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>

//TODO: Where should this file go?
//FIXME: too many global
const double ABS_TEST_THRESHOLD = 1e-10;
const double BOOST_CLOSE_THRESHOLD = 1e-6;

template<typename A>
void boost_check_array(A &expected, A &result, int expected_size) {

BOOST_CHECK_EQUAL(expected_size, expected.size());
BOOST_CHECK_EQUAL(expected.size(), result.size());
for (int i = 0; i < expected.size(); ++i) {
BOOST_CHECK_CLOSE(expected[i], result[i], BOOST_CLOSE_THRESHOLD);
}

}

template<typename M>
void boost_check_matrix(M &expected, M &result, int expected_rows, int expected_cols) {
BOOST_CHECK_EQUAL(expected_rows, expected.rows());
BOOST_CHECK_EQUAL(expected_cols, expected.cols());
BOOST_CHECK_EQUAL(expected.rows(), result.rows());
BOOST_CHECK_EQUAL(expected.cols(), result.cols());

for (int i = 0; i < expected.rows(); ++i) {
for (int j = 0; j < expected.cols(); ++j) {
BOOST_CHECK_CLOSE(expected(i, j), result(i, j), BOOST_CLOSE_THRESHOLD);
}
}
}


template<typename A, typename B>
void AssertTrue(A expected, B actual){
assert(expected==actual);
};

template<typename A>
void AssertNear(A expected, A actual){
assert(((expected - actual)/expected) < ABS_TEST_THRESHOLD);

};

template<typename A>
void AssertEigenMatrixNear(A expected, A actual){
for (int j = 0; j < expected.rows(); ++j) {
for (int k = 0; k < expected.cols(); ++k) {
AssertNear(expected(j,k), actual(j,k));
}
}
};


#endif //DENOVOGEAR_BOOST_TEST_HELPER_H
Loading