Commit 09dd6549 by Maarten L. Hekkelman

Change testing framework to Catch2

parent 640552ab
......@@ -451,17 +451,39 @@ write_basic_package_version_file(
)
if(BUILD_TESTING)
find_package(Boost REQUIRED)
set(CATCH_BUILD_TESTING OFF)
list(APPEND CIFPP_tests unit-v2 unit-3d format model rename-compound sugar spinner)
find_package(Catch2 3 QUIET)
if(NOT Catch2_FOUND)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(Catch2)
endif()
list(APPEND CIFPP_tests
# unit-v2
unit-3d
format
model
rename-compound
sugar
spinner
)
foreach(CIFPP_TEST IN LISTS CIFPP_tests)
set(CIFPP_TEST "${CIFPP_TEST}-test")
set(CIFPP_TEST_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/test/${CIFPP_TEST}.cpp")
add_executable(${CIFPP_TEST} ${CIFPP_TEST_SOURCE})
add_executable(${CIFPP_TEST} ${CIFPP_TEST_SOURCE} "${CMAKE_CURRENT_SOURCE_DIR}/test/test-main.cpp")
target_link_libraries(${CIFPP_TEST} PRIVATE Threads::Threads cifpp::cifpp Boost::boost)
target_link_libraries(${CIFPP_TEST} PRIVATE Threads::Threads cifpp::cifpp Catch2::Catch2)
target_include_directories(${CIFPP_TEST} PRIVATE ${EIGEN_INCLUDE_DIR})
if(MSVC)
......@@ -476,7 +498,7 @@ if(BUILD_TESTING)
COMMAND $<TARGET_FILE:${CIFPP_TEST}> -- ${CMAKE_CURRENT_SOURCE_DIR}/test)
add_test(NAME ${CIFPP_TEST}
COMMAND $<TARGET_FILE:${CIFPP_TEST}> -- ${CMAKE_CURRENT_SOURCE_DIR}/test)
COMMAND $<TARGET_FILE:${CIFPP_TEST}> --data-dir ${CMAKE_CURRENT_SOURCE_DIR}/test)
endforeach()
endif()
......
......@@ -24,69 +24,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/included/unit_test.hpp>
#include <catch2/catch_test_macros.hpp>
#include <stdexcept>
#include <cif++.hpp>
namespace tt = boost::test_tools;
std::filesystem::path gTestDir = std::filesystem::current_path(); // filled in first test
// --------------------------------------------------------------------
cif::file operator""_cf(const char *text, size_t length)
{
struct membuf : public std::streambuf
{
membuf(char *text, size_t length)
{
this->setg(text, text, text + length);
}
} buffer(const_cast<char *>(text), length);
std::istream is(&buffer);
return cif::file(is);
}
// --------------------------------------------------------------------
bool init_unit_test()
{
cif::VERBOSE = 1;
// // not a test, just initialize test dir
// if (boost::unit_test::framework::master_test_suite().argc == 2)
// gTestDir = boost::unit_test::framework::master_test_suite().argv[1];
// // do this now, avoids the need for installing
// cif::add_file_resource("mmcif_pdbx.dic", gTestDir / ".." / "rsrc" / "mmcif_pdbx.dic");
// // initialize CCD location
// cif::add_file_resource("components.cif", gTestDir / ".." / "data" / "ccd-subset.cif");
return true;
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(fmt_1)
TEST_CASE("fmt_1")
{
std::ostringstream os;
std::string world("world");
os << cif::format("Hello, %-10.10s, the magic number is %d and pi is %g", world, 42, cif::kPI);
BOOST_CHECK_EQUAL(os.str(), "Hello, world , the magic number is 42 and pi is 3.14159");
REQUIRE(os.str() == "Hello, world , the magic number is 42 and pi is 3.14159");
BOOST_CHECK_EQUAL(cif::format("Hello, %-10.10s, the magic number is %d and pi is %g", world, 42, cif::kPI).str(),
REQUIRE(cif::format("Hello, %-10.10s, the magic number is %d and pi is %g", world, 42, cif::kPI).str() ==
"Hello, world , the magic number is 42 and pi is 3.14159");
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(clr_1)
TEST_CASE("clr_1")
{
using namespace cif::colour;
......
......@@ -24,8 +24,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/included/unit_test.hpp>
#include "test-main.hpp"
#include <catch2/catch_test_macros.hpp>
#include <stdexcept>
......@@ -33,15 +34,15 @@
// --------------------------------------------------------------------
cif::file operator""_cf(const char* text, size_t length)
cif::file operator""_cf(const char *text, size_t length)
{
struct membuf : public std::streambuf
{
membuf(char* text, size_t length)
membuf(char *text, size_t length)
{
this->setg(text, text, text + length);
}
} buffer(const_cast<char*>(text), length);
} buffer(const_cast<char *>(text), length);
std::istream is(&buffer);
return cif::file(is);
......@@ -49,36 +50,7 @@ cif::file operator""_cf(const char* text, size_t length)
// --------------------------------------------------------------------
std::filesystem::path gTestDir = std::filesystem::current_path();
bool init_unit_test()
{
cif::VERBOSE = 1;
// not a test, just initialize test dir
if (boost::unit_test::framework::master_test_suite().argc == 2)
gTestDir = boost::unit_test::framework::master_test_suite().argv[1];
else
{
while (not gTestDir.empty() and not std::filesystem::exists(gTestDir / "test"))
gTestDir = gTestDir.parent_path();
gTestDir /= "test";
}
// do this now, avoids the need for installing
cif::add_file_resource("mmcif_pdbx.dic", gTestDir / ".." / "rsrc" / "mmcif_pdbx.dic");
// initialize CCD location
cif::add_file_resource("components.cif", gTestDir / ".." / "data" / "ccd-subset.cif");
cif::compound_factory::instance().push_dictionary(gTestDir / "HEM.cif");
return true;
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(create_nonpoly_1)
TEST_CASE("create_nonpoly_1")
{
cif::VERBOSE = 1;
......@@ -119,7 +91,7 @@ _atom_site.pdbx_formal_charge
auto hem_atoms = atom_site.rows();
std::vector<cif::mm::atom> atom_data;
for (auto hem_atom: hem_atoms)
for (auto hem_atom : hem_atoms)
atom_data.emplace_back(hem_data, hem_atom);
structure.create_non_poly(entity_id, atom_data);
......@@ -191,9 +163,9 @@ _atom_type.symbol C
expected.load_dictionary("mmcif_pdbx.dic");
if (not (expected.front() == structure.get_datablock()))
if (not(expected.front() == structure.get_datablock()))
{
BOOST_TEST(false);
REQUIRE(false);
std::cout << expected.front() << '\n'
<< '\n'
<< structure.get_datablock() << '\n';
......@@ -202,7 +174,7 @@ _atom_type.symbol C
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(create_nonpoly_2)
TEST_CASE("create_nonpoly_2")
{
cif::VERBOSE = 1;
......@@ -218,7 +190,7 @@ BOOST_AUTO_TEST_CASE(create_nonpoly_2)
std::vector<cif::row_initializer> atoms;
for (const auto &[type_symbol, label_atom_id, Cartn_x, Cartn_y, Cartn_z] :
chem_comp_atom.rows<std::string,std::string,float,float,float>(
chem_comp_atom.rows<std::string, std::string, float, float, float>(
"type_symbol", "atom_id", "model_Cartn_x", "model_Cartn_y", "model_Cartn_z"))
{
atoms.emplace_back(cif::row_initializer{
......@@ -227,8 +199,7 @@ BOOST_AUTO_TEST_CASE(create_nonpoly_2)
{ "auth_atom_id", label_atom_id },
{ "Cartn_x", Cartn_x },
{ "Cartn_y", Cartn_y },
{ "Cartn_z", Cartn_z }
});
{ "Cartn_z", Cartn_z } });
if (atoms.size() == 4)
break;
......@@ -303,23 +274,23 @@ _atom_type.symbol C
expected.load_dictionary("mmcif_pdbx.dic");
if (not (expected.front() == structure.get_datablock()))
REQUIRE(expected.front() == structure.get_datablock());
if (not(expected.front() == structure.get_datablock()))
{
BOOST_TEST(false);
// REQUIRE(false);
std::cout << expected.front() << '\n'
<< '\n'
<< structure.get_datablock() << '\n';
expected.save("/tmp/a");
file.save("/tmp/b");
}
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(test_atom_id)
TEST_CASE("test_atom_id")
{
auto data = R"(
data_TEST
......@@ -389,15 +360,15 @@ _struct_asym.details ?
cif::mm::structure s(data);
BOOST_CHECK_EQUAL(s.get_atom_by_id("1").get_label_atom_id(), "CHA");
BOOST_CHECK_EQUAL(s.get_atom_by_id("2").get_label_atom_id(), "CHC");
BOOST_CHECK_EQUAL(s.get_atom_by_id("3").get_label_atom_id(), "CHB");
BOOST_CHECK_EQUAL(s.get_atom_by_id("4").get_label_atom_id(), "CHD");
REQUIRE(s.get_atom_by_id("1").get_label_atom_id() == "CHA");
REQUIRE(s.get_atom_by_id("2").get_label_atom_id() == "CHC");
REQUIRE(s.get_atom_by_id("3").get_label_atom_id() == "CHB");
REQUIRE(s.get_atom_by_id("4").get_label_atom_id() == "CHD");
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(atom_numbers_1)
TEST_CASE("atom_numbers_1")
{
const std::filesystem::path test1(gTestDir / ".." / "examples" / "1cbs.cif.gz");
cif::file file(test1.string());
......@@ -409,27 +380,27 @@ BOOST_AUTO_TEST_CASE(atom_numbers_1)
auto ai = atoms.begin();
for (const auto &[id, label_asym_id, label_seq_id, label_atom_id, auth_seq_id, label_comp_id] :
db["atom_site"].rows<std::string,std::string,int,std::string,std::string,std::string>("id", "label_asym_id", "label_seq_id", "label_atom_id", "auth_seq_id", "label_comp_id"))
db["atom_site"].rows<std::string, std::string, int, std::string, std::string, std::string>("id", "label_asym_id", "label_seq_id", "label_atom_id", "auth_seq_id", "label_comp_id"))
{
auto atom = structure.get_atom_by_id(id);
BOOST_CHECK_EQUAL(atom.get_label_asym_id(), label_asym_id);
BOOST_CHECK_EQUAL(atom.get_label_seq_id(), label_seq_id);
BOOST_CHECK_EQUAL(atom.get_label_atom_id(), label_atom_id);
BOOST_CHECK_EQUAL(atom.get_auth_seq_id(), auth_seq_id);
BOOST_CHECK_EQUAL(atom.get_label_comp_id(), label_comp_id);
REQUIRE(atom.get_label_asym_id() == label_asym_id);
REQUIRE(atom.get_label_seq_id() == label_seq_id);
REQUIRE(atom.get_label_atom_id() == label_atom_id);
REQUIRE(atom.get_auth_seq_id() == auth_seq_id);
REQUIRE(atom.get_label_comp_id() == label_comp_id);
BOOST_ASSERT(ai != atoms.end());
REQUIRE(ai != atoms.end());
BOOST_CHECK_EQUAL(ai->id(), id);
REQUIRE(ai->id() == id);
++ai;
}
BOOST_ASSERT(ai == atoms.end());
REQUIRE(ai == atoms.end());
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(test_load_2)
TEST_CASE("test_load_2")
{
using namespace cif::literals;
......@@ -440,17 +411,17 @@ BOOST_AUTO_TEST_CASE(test_load_2)
cif::mm::structure s(file);
BOOST_CHECK(s.polymers().size() == 1);
REQUIRE(s.polymers().size() == 1UL);
auto &pdbx_poly_seq_scheme = db["pdbx_poly_seq_scheme"];
for (auto &poly : s.polymers())
{
BOOST_CHECK_EQUAL(poly.size(), pdbx_poly_seq_scheme.find("asym_id"_key == poly.get_asym_id()).size());
REQUIRE(poly.size() == pdbx_poly_seq_scheme.find("asym_id"_key == poly.get_asym_id()).size());
}
}
BOOST_AUTO_TEST_CASE(remove_residue_1)
TEST_CASE("remove_residue_1")
{
using namespace cif::literals;
......@@ -460,5 +431,5 @@ BOOST_AUTO_TEST_CASE(remove_residue_1)
cif::mm::structure s(file);
s.remove_residue(s.get_residue("B"));
BOOST_CHECK_NO_THROW(s.validate_atoms());
REQUIRE_NOTHROW(s.validate_atoms());
}
......@@ -24,38 +24,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "test-main.hpp"
#include <cif++.hpp>
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include <fstream>
int main(int argc, char* argv[])
TEST_CASE("rename")
{
cif::VERBOSE = 3;
try
{
std::filesystem::path testdir = std::filesystem::current_path();
if (argc == 3)
testdir = argv[2];
else
{
while (not testdir.empty() and not std::filesystem::exists(testdir / "test"))
testdir = testdir.parent_path();
testdir /= "test";
}
if (std::filesystem::exists(gTestDir / ".." / "data" / "ccd-subset.cif"))
cif::add_file_resource("components.cif", gTestDir / ".." / "data" / "ccd-subset.cif");
if (std::filesystem::exists(testdir / ".." / "data" / "ccd-subset.cif"))
cif::add_file_resource("components.cif", testdir / ".." / "data" / "ccd-subset.cif");
if (std::filesystem::exists(gTestDir / ".." / "rsrc" / "mmcif_pdbx.dic"))
cif::add_file_resource("mmcif_pdbx.dic", gTestDir / ".." / "rsrc" / "mmcif_pdbx.dic");
if (std::filesystem::exists(testdir / ".." / "rsrc" / "mmcif_pdbx.dic"))
cif::add_file_resource("mmcif_pdbx.dic", testdir / ".." / "rsrc" / "mmcif_pdbx.dic");
cif::compound_factory::instance().push_dictionary(gTestDir / "REA.cif");
cif::compound_factory::instance().push_dictionary(gTestDir / "RXA.cif");
cif::compound_factory::instance().push_dictionary(testdir / "REA.cif");
cif::compound_factory::instance().push_dictionary(testdir / "RXA.cif");
cif::file f(testdir / ".."/"examples"/"1cbs.cif.gz");
cif::file f(gTestDir / ".."/"examples"/"1cbs.cif.gz");
cif::mm::structure structure(f);
auto &res = structure.get_residue("B");
......@@ -69,12 +60,4 @@ int main(int argc, char* argv[])
throw std::runtime_error("Invalid");
f.save(std::cout);
}
catch (const std::exception& e)
{
std::cerr << e.what() << '\n';
exit(1);
}
return 0;
}
#include "cif++/utilities.hpp"
#include <catch2/catch_test_macros.hpp>
#include <random>
#include <thread>
void test_one()
TEST_CASE("test_one")
{
std::random_device rd;
std::mt19937 gen(rd());
......@@ -20,7 +22,7 @@ void test_one()
}
}
void test_two()
TEST_CASE("test_two")
{
cif::progress_bar pb(10, "test");
......@@ -29,7 +31,7 @@ void test_two()
pb.consumed(1);
}
void test_three()
TEST_CASE("test_three")
{
using namespace std::literals;
......@@ -38,12 +40,3 @@ void test_three()
std::this_thread::sleep_for(100ms);
}
int main()
{
test_one();
test_two();
test_three();
return 0;
}
\ No newline at end of file
......@@ -24,8 +24,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/included/unit_test.hpp>
#include "test-main.hpp"
#include <catch2/catch_test_macros.hpp>
#include <stdexcept>
......@@ -49,30 +50,7 @@ cif::file operator""_cf(const char* text, size_t length)
// --------------------------------------------------------------------
std::filesystem::path gTestDir = std::filesystem::current_path();
bool init_unit_test()
{
cif::VERBOSE = 1;
// not a test, just initialize test dir
if (boost::unit_test::framework::master_test_suite().argc == 2)
gTestDir = boost::unit_test::framework::master_test_suite().argv[1];
// do this now, avoids the need for installing
cif::add_file_resource("mmcif_pdbx.dic", gTestDir / ".." / "rsrc" / "mmcif_pdbx.dic");
// initialize CCD location
cif::add_file_resource("components.cif", gTestDir / ".." / "data" / "ccd-subset.cif");
cif::compound_factory::instance().push_dictionary(gTestDir / "HEM.cif");
return true;
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(sugar_name_1)
TEST_CASE("sugar_name_1")
{
using namespace cif::literals;
......@@ -85,20 +63,20 @@ BOOST_AUTO_TEST_CASE(sugar_name_1)
auto &branches = s.branches();
BOOST_CHECK_EQUAL(branches.size(), 4);
REQUIRE(branches.size() == 4UL);
for (auto &branch : branches)
{
auto entityID = branch.front().get_entity_id();
auto name = entity.find1<std::string>("id"_key == entityID, "pdbx_description");
BOOST_CHECK_EQUAL(branch.name(), name);
REQUIRE(branch.name() == name);
}
}
// // --------------------------------------------------------------------
// BOOST_AUTO_TEST_CASE(create_sugar_1)
// TEST_CASE("create_sugar_1")
// {
// using namespace cif::literals;
......@@ -125,19 +103,19 @@ BOOST_AUTO_TEST_CASE(sugar_name_1)
// auto &branch = s.create_branch(ai);
// BOOST_CHECK_EQUAL(branch.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose");
// BOOST_CHECK_EQUAL(branch.size(), 1);
// REQUIRE(branch.name() == "2-acetamido-2-deoxy-beta-D-glucopyranose");
// REQUIRE(branch.size() == 1);
// BOOST_CHECK_EQUAL(branch[0].atoms().size(), nagAtoms.size());
// REQUIRE(branch[0].atoms().size() == nagAtoms.size());
// BOOST_CHECK(file.is_valid());
// REQUIRE(file.is_valid());
// file.save(gTestDir / "test-create_sugar_1.cif");
// }
// // --------------------------------------------------------------------
// BOOST_AUTO_TEST_CASE(create_sugar_2)
// TEST_CASE("create_sugar_2")
// {
// using namespace cif::literals;
......@@ -148,7 +126,7 @@ BOOST_AUTO_TEST_CASE(sugar_name_1)
// // Get branch for H
// auto &bH = s.get_branch_by_asym_id("H");
// BOOST_CHECK_EQUAL(bH.size(), 2);
// REQUIRE(bH.size() == 2);
// std::vector<cif::row_initializer> ai[2];
......@@ -163,24 +141,24 @@ BOOST_AUTO_TEST_CASE(sugar_name_1)
// s.remove_branch(bH);
// BOOST_CHECK(file.is_valid());
// REQUIRE(file.is_valid());
// auto &bN = s.create_branch(ai[0]);
// s.extend_branch(bN.get_asym_id(), ai[1], 1, "O4");
// BOOST_CHECK_EQUAL(bN.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose-(1-4)-2-acetamido-2-deoxy-beta-D-glucopyranose");
// BOOST_CHECK_EQUAL(bN.size(), 2);
// REQUIRE(bN.name() == "2-acetamido-2-deoxy-beta-D-glucopyranose-(1-4)-2-acetamido-2-deoxy-beta-D-glucopyranose");
// REQUIRE(bN.size() == 2);
// BOOST_CHECK(file.is_valid());
// REQUIRE(file.is_valid());
// file.save(gTestDir / "test-create_sugar_2.cif");
// BOOST_CHECK_NO_THROW(cif::mm::structure s2(file));
// REQUIRE_NO_THROW(cif::mm::structure s2(file));
// }
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(delete_sugar_1)
TEST_CASE("delete_sugar_1")
{
using namespace cif::literals;
......@@ -191,20 +169,20 @@ BOOST_AUTO_TEST_CASE(delete_sugar_1)
// Get branch for H
auto &bG = s.get_branch_by_asym_id("G");
BOOST_CHECK_EQUAL(bG.size(), 4);
REQUIRE(bG.size() == 4UL);
s.remove_residue(bG[1]);
BOOST_CHECK_EQUAL(bG.size(), 1);
REQUIRE(bG.size() == 1UL);
auto &bN = s.get_branch_by_asym_id("G");
BOOST_CHECK_EQUAL(bN.name(), "2-acetamido-2-deoxy-beta-D-glucopyranose");
BOOST_CHECK_EQUAL(bN.size(), 1);
REQUIRE(bN.name() == "2-acetamido-2-deoxy-beta-D-glucopyranose");
REQUIRE(bN.size() == 1UL);
BOOST_CHECK(file.is_valid());
REQUIRE(file.is_valid());
// file.save(gTestDir / "test-create_sugar_3.cif");
BOOST_CHECK_NO_THROW(cif::mm::structure s2(file));
cif::mm::structure s2(file);
}
#include "test-main.hpp"
#include <cif++.hpp>
#include <catch2/catch_session.hpp>
std::filesystem::path gTestDir = std::filesystem::current_path();
int main(int argc, char *argv[])
{
Catch::Session session; // There must be exactly one instance
// Build a new parser on top of Catch2's
using namespace Catch::Clara;
auto cli = session.cli() // Get Catch2's command line parser
| Opt(gTestDir, "data-dir") // bind variable to a new option, with a hint string
["-D"]["--data-dir"] // the option names it will respond to
("The directory containing the data files"); // description string for the help output
// Now pass the new composite back to Catch2 so it uses that
session.cli(cli);
// Let Catch2 (using Clara) parse the command line
int returnCode = session.applyCommandLine(argc, argv);
if (returnCode != 0) // Indicates a command line error
return returnCode;
// do this now, avoids the need for installing
cif::add_file_resource("mmcif_pdbx.dic", gTestDir / ".." / "rsrc" / "mmcif_pdbx.dic");
// initialize CCD location
cif::add_file_resource("components.cif", gTestDir / ".." / "data" / "ccd-subset.cif");
cif::compound_factory::instance().push_dictionary(gTestDir / "HEM.cif");
return session.run();
}
\ No newline at end of file
#include <filesystem>
extern std::filesystem::path gTestDir;
......@@ -24,8 +24,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/included/unit_test.hpp>
#include "test-main.hpp"
#include <catch2/catch_test_macros.hpp>
#include <stdexcept>
......@@ -33,11 +34,6 @@
#include <Eigen/Eigenvalues>
namespace tt = boost::test_tools;
namespace utf = boost::unit_test;
std::filesystem::path gTestDir = std::filesystem::current_path(); // filled in first test
// --------------------------------------------------------------------
cif::file operator""_cf(const char *text, size_t length)
......@@ -56,28 +52,9 @@ cif::file operator""_cf(const char *text, size_t length)
// --------------------------------------------------------------------
bool init_unit_test()
{
cif::VERBOSE = 1;
// not a test, just initialize test dir
if (boost::unit_test::framework::master_test_suite().argc == 2)
gTestDir = boost::unit_test::framework::master_test_suite().argv[1];
// do this now, avoids the need for installing
cif::add_file_resource("mmcif_pdbx.dic", gTestDir / ".." / "rsrc" / "mmcif_pdbx.dic");
// initialize CCD location
cif::add_file_resource("components.cif", gTestDir / ".." / "data" / "ccd-subset.cif");
return true;
}
// --------------------------------------------------------------------
// 3d tests
BOOST_AUTO_TEST_CASE(t1)
TEST_CASE("t1")
{
// std::random_device rnd;
// std::mt19937 gen(rnd());
......@@ -115,19 +92,20 @@ BOOST_AUTO_TEST_CASE(t1)
const auto &&[angle, axis] = cif::quaternion_to_angle_axis(q2);
BOOST_TEST(std::fmod(360 + angle, 360) == std::fmod(360 - angle0, 360), tt::tolerance(0.01));
// REQUIRE(std::fmod(360 + angle, 360) == std::fmod(360 - angle0, 360)/*, tt::tolerance(0.01)*/);
REQUIRE(std::fmod(360 + angle, 360) == std::fmod(360 - angle0, 360));
for (auto &p : p1)
p.rotate(q2);
auto rmsd = cif::RMSd(p1, p2);
BOOST_TEST(rmsd < 1e-5);
REQUIRE(rmsd < 1e-5);
// std::cout << "rmsd: " << RMSd(p1, p2) << '\n';
}
BOOST_AUTO_TEST_CASE(t2)
TEST_CASE("t2")
{
cif::point p[] = {
{ 1, 1, 0 },
......@@ -141,10 +119,11 @@ BOOST_AUTO_TEST_CASE(t2)
auto &&[angle, axis] = cif::quaternion_to_angle_axis(q);
BOOST_TEST(angle == 45, tt::tolerance(0.01));
// REQUIRE(angle == 45/*, tt::tolerance(0.01)*/);
REQUIRE(angle == 45);
}
BOOST_AUTO_TEST_CASE(t3)
TEST_CASE("t3")
{
cif::point p[] = {
{ 1, 1, 0 },
......@@ -165,10 +144,11 @@ BOOST_AUTO_TEST_CASE(t3)
double a = cif::angle(v, p[0], p[1]);
BOOST_TEST(a == 45, tt::tolerance(0.01));
// REQUIRE(a == 45/*, tt::tolerance(0.01)*/);
REQUIRE(a == 45);
}
BOOST_AUTO_TEST_CASE(dh_q_0)
TEST_CASE("dh_q_0")
{
cif::point axis(1, 0, 0);
......@@ -182,33 +162,33 @@ BOOST_AUTO_TEST_CASE(dh_q_0)
};
auto a = cif::dihedral_angle(t[0], t[1], t[2], p);
BOOST_TEST(a == 0, tt::tolerance(0.01f));
REQUIRE(a == 0/*, tt::tolerance(0.01f)*/);
auto q = cif::construct_from_angle_axis(90, axis);
p.rotate(q);
BOOST_TEST(p.m_x == 1, tt::tolerance(0.01f));
BOOST_TEST(p.m_y == 0, tt::tolerance(0.01f));
BOOST_TEST(p.m_z == 1, tt::tolerance(0.01f));
REQUIRE(p.m_x == 1/*, tt::tolerance(0.01f)*/);
REQUIRE(p.m_y == 0/*, tt::tolerance(0.01f)*/);
REQUIRE(p.m_z == 1/*, tt::tolerance(0.01f)*/);
a = cif::dihedral_angle(t[0], t[1], t[2], p);
BOOST_TEST(a == 90, tt::tolerance(0.01f));
REQUIRE(a == 90/*, tt::tolerance(0.01f)*/);
q = cif::construct_from_angle_axis(-90, axis);
p.rotate(q);
BOOST_TEST(p.m_x == 1, tt::tolerance(0.01f));
BOOST_TEST(p.m_y == 1, tt::tolerance(0.01f));
BOOST_TEST(p.m_z == 0, tt::tolerance(0.01f));
REQUIRE(p.m_x == 1/*, tt::tolerance(0.01f)*/);
REQUIRE(p.m_y == 1/*, tt::tolerance(0.01f)*/);
REQUIRE(p.m_z == 0/*, tt::tolerance(0.01f)*/);
a = cif::dihedral_angle(t[0], t[1], t[2], p);
BOOST_TEST(a == 0, tt::tolerance(0.01f));
REQUIRE(a == 0/*, tt::tolerance(0.01f)*/);
}
BOOST_AUTO_TEST_CASE(dh_q_1)
TEST_CASE("dh_q_1")
{
struct
{
......@@ -247,13 +227,13 @@ BOOST_AUTO_TEST_CASE(dh_q_1)
pts[3].rotate(q, pts[2]);
auto dh = cif::dihedral_angle(pts[0], pts[1], pts[2], pts[3]);
BOOST_TEST(dh == angle, tt::tolerance(0.1f));
REQUIRE(dh == angle/*, tt::tolerance(0.1f)*/);
}
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(m2q_0, *utf::tolerance(0.001f))
TEST_CASE("m2q_0, *utf::tolerance(0.001f)")
{
for (size_t i = 0; i < cif::kSymopNrTableSize; ++i)
{
......@@ -310,13 +290,13 @@ BOOST_AUTO_TEST_CASE(m2q_0, *utf::tolerance(0.001f))
cif::point p3 = rot * p1;
BOOST_TEST(p2.m_x == p3.m_x);
BOOST_TEST(p2.m_y == p3.m_y);
BOOST_TEST(p2.m_z == p3.m_z);
REQUIRE(p2.m_x == p3.m_x);
REQUIRE(p2.m_y == p3.m_y);
REQUIRE(p2.m_z == p3.m_z);
}
}
// BOOST_AUTO_TEST_CASE(m2q_1, *utf::tolerance(0.001f))
// "TEST_CASE(m2q_1, *utf::tolerance(0.001f)")
// {
// for (size_t i = 0; i < cif::kSymopNrTableSize; ++i)
// {
......@@ -369,15 +349,15 @@ BOOST_AUTO_TEST_CASE(m2q_0, *utf::tolerance(0.001f))
// cif::point p3 = rot * p1;
// BOOST_TEST(p2.m_x == p3.m_x);
// BOOST_TEST(p2.m_y == p3.m_y);
// BOOST_TEST(p2.m_z == p3.m_z);
// REQUIRE(p2.m_x == p3.m_x);
// REQUIRE(p2.m_y == p3.m_y);
// REQUIRE(p2.m_z == p3.m_z);
// }
// }
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(symm_1)
TEST_CASE("symm_1")
{
cif::cell c(10, 10, 10);
......@@ -385,37 +365,37 @@ BOOST_AUTO_TEST_CASE(symm_1)
cif::point f = fractional(p, c);
BOOST_TEST(f.m_x == 0.1f, tt::tolerance(0.01));
BOOST_TEST(f.m_y == 0.1f, tt::tolerance(0.01));
BOOST_TEST(f.m_z == 0.1f, tt::tolerance(0.01));
REQUIRE(f.m_x == 0.1f/*, tt::tolerance(0.01)*/);
REQUIRE(f.m_y == 0.1f/*, tt::tolerance(0.01)*/);
REQUIRE(f.m_z == 0.1f/*, tt::tolerance(0.01)*/);
cif::point o = orthogonal(f, c);
BOOST_TEST(o.m_x == 1.f, tt::tolerance(0.01));
BOOST_TEST(o.m_y == 1.f, tt::tolerance(0.01));
BOOST_TEST(o.m_z == 1.f, tt::tolerance(0.01));
REQUIRE(o.m_x == 1.f/*, tt::tolerance(0.01)*/);
REQUIRE(o.m_y == 1.f/*, tt::tolerance(0.01)*/);
REQUIRE(o.m_z == 1.f/*, tt::tolerance(0.01)*/);
}
BOOST_AUTO_TEST_CASE(symm_2)
TEST_CASE("symm_2")
{
using namespace cif::literals;
auto symop = "1_555"_symop;
BOOST_TEST(symop.is_identity() == true);
REQUIRE(symop.is_identity() == true);
}
BOOST_AUTO_TEST_CASE(symm_3)
TEST_CASE("symm_3")
{
using namespace cif::literals;
cif::spacegroup sg(18);
BOOST_TEST(sg.size() == 4);
BOOST_TEST(sg.get_name() == "P 21 21 2");
REQUIRE(sg.size() == 4UL);
REQUIRE(sg.get_name() == "P 21 21 2");
}
BOOST_AUTO_TEST_CASE(symm_4, *utf::tolerance(0.1f))
TEST_CASE("symm_4, *utf::tolerance(0.1f)")
{
using namespace cif::literals;
......@@ -427,21 +407,21 @@ BOOST_AUTO_TEST_CASE(symm_4, *utf::tolerance(0.1f))
cif::point b{ -35.356, 33.693, -3.236 }; // CG2 THR D 400
cif::point sb( -6.916, 79.34, 3.236); // 4_565 copy of b
BOOST_TEST(distance(a, sg(a, c, "1_455"_symop)) == static_cast<float>(c.get_a()));
BOOST_TEST(distance(a, sg(a, c, "1_545"_symop)) == static_cast<float>(c.get_b()));
BOOST_TEST(distance(a, sg(a, c, "1_554"_symop)) == static_cast<float>(c.get_c()));
REQUIRE(distance(a, sg(a, c, "1_455"_symop)) == static_cast<float>(c.get_a()));
REQUIRE(distance(a, sg(a, c, "1_545"_symop)) == static_cast<float>(c.get_b()));
REQUIRE(distance(a, sg(a, c, "1_554"_symop)) == static_cast<float>(c.get_c()));
auto sb2 = sg(b, c, "4_565"_symop);
BOOST_TEST(sb.m_x == sb2.m_x);
BOOST_TEST(sb.m_y == sb2.m_y);
BOOST_TEST(sb.m_z == sb2.m_z);
REQUIRE(sb.m_x == sb2.m_x);
REQUIRE(sb.m_y == sb2.m_y);
REQUIRE(sb.m_z == sb2.m_z);
BOOST_TEST(distance(a, sb2) == 7.42f);
REQUIRE(distance(a, sb2) == 7.42f);
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(symm_4wvp_1, *utf::tolerance(0.1f))
TEST_CASE("symm_4wvp_1, *utf::tolerance(0.1f)")
{
using namespace cif::literals;
......@@ -456,21 +436,21 @@ BOOST_AUTO_TEST_CASE(symm_4wvp_1, *utf::tolerance(0.1f))
auto a = s.get_residue("A", 10, "").get_atom_by_atom_id("O");
auto sp1 = c.symmetry_copy(a.get_location(), "2_565"_symop);
BOOST_TEST(sp1.m_x == p.m_x);
BOOST_TEST(sp1.m_y == p.m_y);
BOOST_TEST(sp1.m_z == p.m_z);
REQUIRE(sp1.m_x == p.m_x);
REQUIRE(sp1.m_y == p.m_y);
REQUIRE(sp1.m_z == p.m_z);
const auto &[d, sp2, so] = c.closest_symmetry_copy(p, a.get_location());
BOOST_TEST(d < 1);
REQUIRE(d < 1);
BOOST_TEST(sp2.m_x == p.m_x);
BOOST_TEST(sp2.m_y == p.m_y);
BOOST_TEST(sp2.m_z == p.m_z);
REQUIRE(sp2.m_x == p.m_x);
REQUIRE(sp2.m_y == p.m_y);
REQUIRE(sp2.m_z == p.m_z);
}
BOOST_AUTO_TEST_CASE(symm_2bi3_1, *utf::tolerance(0.1f))
TEST_CASE("symm_2bi3_1, *utf::tolerance(0.1f)")
{
cif::file f(gTestDir / "2bi3.cif.gz");
......@@ -502,22 +482,22 @@ BOOST_AUTO_TEST_CASE(symm_2bi3_1, *utf::tolerance(0.1f))
auto sa1 = c.symmetry_copy(a1.get_location(), cif::sym_op(symm1));
auto sa2 = c.symmetry_copy(a2.get_location(), cif::sym_op(symm2));
BOOST_TEST(cif::distance(sa1, sa2) == dist);
REQUIRE(cif::distance(sa1, sa2) == dist);
auto pa1 = a1.get_location();
const auto &[d, p, so] = c.closest_symmetry_copy(pa1, a2.get_location());
BOOST_TEST(p.m_x == sa2.m_x);
BOOST_TEST(p.m_y == sa2.m_y);
BOOST_TEST(p.m_z == sa2.m_z);
REQUIRE(p.m_x == sa2.m_x);
REQUIRE(p.m_y == sa2.m_y);
REQUIRE(p.m_z == sa2.m_z);
BOOST_TEST(d == dist);
BOOST_TEST(so.string() == symm2);
REQUIRE(d == dist);
REQUIRE(so.string() == symm2);
}
}
BOOST_AUTO_TEST_CASE(symm_2bi3_1a, *utf::tolerance(0.1f))
TEST_CASE("symm_2bi3_1a, *utf::tolerance(0.1f)")
{
using namespace cif::literals;
......@@ -552,20 +532,20 @@ BOOST_AUTO_TEST_CASE(symm_2bi3_1a, *utf::tolerance(0.1f))
auto sa1 = c.symmetry_copy(p1, cif::sym_op(symm1));
auto sa2 = c.symmetry_copy(p2, cif::sym_op(symm2));
BOOST_TEST(cif::distance(sa1, sa2) == dist);
REQUIRE(cif::distance(sa1, sa2) == dist);
const auto &[d, p, so] = c.closest_symmetry_copy(p1, p2);
BOOST_TEST(p.m_x == sa2.m_x);
BOOST_TEST(p.m_y == sa2.m_y);
BOOST_TEST(p.m_z == sa2.m_z);
REQUIRE(p.m_x == sa2.m_x);
REQUIRE(p.m_y == sa2.m_y);
REQUIRE(p.m_z == sa2.m_z);
BOOST_TEST(d == dist);
BOOST_TEST(so.string() == symm2);
REQUIRE(d == dist);
REQUIRE(so.string() == symm2);
}
}
BOOST_AUTO_TEST_CASE(symm_3bwh_1, *utf::tolerance(0.1f))
TEST_CASE("symm_3bwh_1, *utf::tolerance(0.1f)")
{
cif::file f(gTestDir / "3bwh.cif.gz");
......@@ -583,12 +563,12 @@ BOOST_AUTO_TEST_CASE(symm_3bwh_1, *utf::tolerance(0.1f))
const auto&[ d, p, so ] = c.closest_symmetry_copy(a1.get_location(), a2.get_location());
BOOST_TEST(d == distance(a1.get_location(), p));
REQUIRE(d == distance(a1.get_location(), p));
}
}
}
BOOST_AUTO_TEST_CASE(volume_3bwh_1, *utf::tolerance(0.1f))
TEST_CASE("volume_3bwh_1, *utf::tolerance(0.1f)")
{
cif::file f(gTestDir / "1juh.cif.gz");
......@@ -596,6 +576,6 @@ BOOST_AUTO_TEST_CASE(volume_3bwh_1, *utf::tolerance(0.1f))
cif::crystal c(db);
BOOST_CHECK_EQUAL(c.get_cell().get_volume(), 741009.625f);
REQUIRE(c.get_cell().get_volume() == 741009.625f);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment