Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
09dd6549
Unverified
Commit
09dd6549
authored
Nov 22, 2023
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change testing framework to Catch2
parent
640552ab
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
262 additions
and
334 deletions
+262
-334
CMakeLists.txt
+27
-5
test/format-test.cpp
+5
-45
test/model-test.cpp
+59
-88
test/rename-compound-test.cpp
+20
-37
test/spinner-test.cpp
+5
-13
test/sugar-test.cpp
+25
-47
test/test-main.cpp
+39
-0
test/test-main.hpp
+3
-0
test/unit-3d-test.cpp
+79
-99
No files found.
CMakeLists.txt
View file @
09dd6549
...
...
@@ -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
()
...
...
test/format-test.cpp
View file @
09dd6549
...
...
@@ -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
;
...
...
test/model-test.cpp
View file @
09dd6549
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
*
* Copyright (c) 2021 NKI/AVL, Netherlands Cancer Institute
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
...
...
@@ -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,59 +34,30 @@
// --------------------------------------------------------------------
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
)
{
this
->
setg
(
text
,
text
,
text
+
length
);
}
}
buffer
(
const_cast
<
char
*>
(
text
),
length
);
std
::
istream
is
(
&
buffer
);
return
cif
::
file
(
is
);
}
// --------------------------------------------------------------------
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
struct
membuf
:
public
std
::
streambuf
{
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
;
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
);
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE
(
create_nonpoly_1
)
TEST_CASE
(
"create_nonpoly_1"
)
{
cif
::
VERBOSE
=
1
;
cif
::
VERBOSE
=
1
;
cif
::
file
file
;
file
.
load_dictionary
(
"mmcif_pdbx.dic"
);
file
.
emplace
(
"TEST"
);
// create a datablock
file
.
emplace
(
"TEST"
);
// create a datablock
cif
::
mm
::
structure
structure
(
file
);
std
::
string
entity_id
=
structure
.
create_non_poly_entity
(
"HEM"
);
...
...
@@ -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,25 +163,25 @@ _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'
;
<<
'\n'
<<
structure
.
get_datablock
()
<<
'\n'
;
}
}
// --------------------------------------------------------------------
BOOST_AUTO_TEST_CASE
(
create_nonpoly_2
)
TEST_CASE
(
"create_nonpoly_2"
)
{
cif
::
VERBOSE
=
1
;
cif
::
VERBOSE
=
1
;
cif
::
file
file
;
file
.
load_dictionary
(
"mmcif_pdbx.dic"
);
file
.
emplace
(
"TEST"
);
// create a datablock
file
.
emplace
(
"TEST"
);
// create a datablock
cif
::
mm
::
structure
structure
(
file
);
cif
::
file
lig
(
gTestDir
/
"HEM.cif"
);
...
...
@@ -218,8 +190,8 @@ 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
>
(
"type_symbol"
,
"atom_id"
,
"model_Cartn_x"
,
"model_Cartn_y"
,
"model_Cartn_z"
))
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
{
{
"type_symbol"
,
type_symbol
},
...
...
@@ -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'
;
<<
'\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_NO
THROW
(
s
.
validate_atoms
());
}
test/rename-compound-test.cpp
View file @
09dd6549
...
...
@@ -24,57 +24,40 @@
* 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
(
testdir
/
".."
/
"data"
/
"ccd-subset.cif"
))
cif
::
add_file_resource
(
"components.cif"
,
testdir
/
".."
/
"data"
/
"ccd-subset.cif"
);
if
(
std
::
filesystem
::
exists
(
gTestDir
/
".."
/
"data"
/
"ccd-subset.cif"
))
cif
::
add_file_resource
(
"components.cif"
,
gTestDir
/
".."
/
"data"
/
"ccd-subset.cif"
);
if
(
std
::
filesystem
::
exists
(
testd
ir
/
".."
/
"rsrc"
/
"mmcif_pdbx.dic"
))
cif
::
add_file_resource
(
"mmcif_pdbx.dic"
,
testd
ir
/
".."
/
"rsrc"
/
"mmcif_pdbx.dic"
);
if
(
std
::
filesystem
::
exists
(
gTestD
ir
/
".."
/
"rsrc"
/
"mmcif_pdbx.dic"
))
cif
::
add_file_resource
(
"mmcif_pdbx.dic"
,
gTestD
ir
/
".."
/
"rsrc"
/
"mmcif_pdbx.dic"
);
cif
::
compound_factory
::
instance
().
push_dictionary
(
testd
ir
/
"REA.cif"
);
cif
::
compound_factory
::
instance
().
push_dictionary
(
testd
ir
/
"RXA.cif"
);
cif
::
compound_factory
::
instance
().
push_dictionary
(
gTestD
ir
/
"REA.cif"
);
cif
::
compound_factory
::
instance
().
push_dictionary
(
gTestD
ir
/
"RXA.cif"
);
cif
::
file
f
(
testd
ir
/
".."
/
"examples"
/
"1cbs.cif.gz"
);
cif
::
mm
::
structure
structure
(
f
);
cif
::
file
f
(
gTestD
ir
/
".."
/
"examples"
/
"1cbs.cif.gz"
);
cif
::
mm
::
structure
structure
(
f
);
auto
&
res
=
structure
.
get_residue
(
"B"
);
structure
.
change_residue
(
res
,
"RXA"
,
{});
auto
&
res
=
structure
.
get_residue
(
"B"
);
structure
.
change_residue
(
res
,
"RXA"
,
{});
structure
.
cleanup_empty_categories
();
structure
.
cleanup_empty_categories
();
f
.
save
(
std
::
cout
);
f
.
save
(
std
::
cout
);
if
(
not
f
.
is_valid
())
throw
std
::
runtime_error
(
"Invalid"
);
if
(
not
f
.
is_valid
())
throw
std
::
runtime_error
(
"Invalid"
);
f
.
save
(
std
::
cout
);
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
'\n'
;
exit
(
1
);
}
return
0
;
f
.
save
(
std
::
cout
);
}
test/spinner-test.cpp
View file @
09dd6549
#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
(
100
ms
);
}
int
main
()
{
test_one
();
test_two
();
test_three
();
return
0
;
}
\ No newline at end of file
test/sugar-test.cpp
View file @
09dd6549
...
...
@@ -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
);
}
test/test-main.cpp
0 → 100644
View file @
09dd6549
#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
test/test-main.hpp
0 → 100644
View file @
09dd6549
#include <filesystem>
extern
std
::
filesystem
::
path
gTestDir
;
test/unit-3d-test.cpp
View file @
09dd6549
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment