Commit f0753f40 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add description_component and unit tests

parent b922fe69
//----------------------------------------------------------------------------//
// Copyright (c) 2018 Armin Sobhani <arminms@gmail.com>
//
// Distributed under the Boost Software License Version 1.0.
// (See accompanying ${file} LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//----------------------------------------------------------------------------//
#ifndef BOOST_BIOSEQ_COMPONENTS_DESCRIPTION_HPP
#define BOOST_BIOSEQ_COMPONENTS_DESCRIPTION_HPP
namespace boost {
namespace bioseq {
namespace component {
//----------------------------------------------------------------------------//
template <typename CharT = char>
class description_component
{
public:
/// \name Construction
//@{
description_component()
{}
//@}
/// \name Attributes
//@{
std::basic_string<CharT> description() const
{ return _description; }
void description(std::basic_string<CharT> dscr)
{ _description = dscr; }
//@}
// Implementation
protected:
std::basic_string<CharT> _description;
};
template <typename CharT = char>
using description = description_component<CharT>;
//----------------------------------------------------------------------------//
} // end component namespace
} // end bioseq namespace
} // end boost namespace
#endif // BOOST_BIOSEQ_COMPONENTS_DESCRIPTION_HPP
......@@ -45,8 +45,9 @@ struct has_##component \
//----------------------------------------------------------------------------//
GENERATE_HAS_COMPONENT(c_str) // create has_c_str
GENERATE_HAS_COMPONENT(name_component) // create has_name_component
GENERATE_HAS_COMPONENT(c_str) // create has_c_str
GENERATE_HAS_COMPONENT(name_component) // create has_name_component
GENERATE_HAS_COMPONENT(description_component)// create has_description_component
//----------------------------------------------------------------------------//
......
......@@ -68,6 +68,7 @@ public:
{
// std::cout << "copy called" << std::endl;
copy_name(other, has_name_component<self_type>());
copy_dscr(other, has_description_component<self_type>());
}
sequence_host(
......@@ -79,6 +80,9 @@ public:
move_name(
std::forward<sequence_host>(other)
, has_name_component<self_type>() );
move_dscr(
std::forward<sequence_host>(other)
, has_description_component<self_type>() );
}
sequence_host(
......@@ -92,11 +96,19 @@ public:
{ self_type::_name = other._name; }
void copy_name(const sequence_host& other, std::false_type)
{}
void copy_dscr(const sequence_host& other, std::true_type)
{ self_type::_description = other._description; }
void copy_dscr(const sequence_host& other, std::false_type)
{}
void move_name(sequence_host&& other, std::true_type)
{ self_type::_name = std::move(other._name); }
void move_name(sequence_host&& other, std::false_type)
{}
void move_dscr(sequence_host&& other, std::true_type)
{ self_type::_description = std::move(other._description); }
void move_dscr(sequence_host&& other, std::false_type)
{}
};
//----------------------------------------------------------------------------//
......
......@@ -48,4 +48,5 @@ endfunction()
add_bioseq_test("sequence" test_sequence.cpp)
add_bioseq_test("name.component" test_name_component.cpp)
add_bioseq_test("description.component" test_description_component.cpp)
add_bioseq_test("io.fasta" test_io_fasta.cpp)
//----------------------------------------------------------------------------//
// Copyright (c) 2018 Armin Sobhani <arminms@gmail.com>
//
// Distributed under the Boost Software License Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//----------------------------------------------------------------------------//
#define BOOST_TEST_MODULE TestDescriptionComponent
#include <boost/mpl/list.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/bioseq/type_traits.hpp>
#include <boost/bioseq/components/description.hpp>
#include <boost/bioseq/sequence.hpp>
namespace bsq = boost::bioseq;
typedef
bsq::sequence_host
<
char
, std::allocator
, std::vector
, bsq::component::description<>
> seq;
typedef
bsq::sequence_host
<
char
, std::allocator
, std::vector
> seq_nodscr;
// adding sequence types to the test list
typedef boost::mpl::list<seq> seq_type;
typedef boost::mpl::list<seq_nodscr> seqnd_type;
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor, T, seq_type)
{
T s;
s.description("copied");
T c(s);
BOOST_CHECK( s.empty() );
BOOST_CHECK_EQUAL( s.description(), "copied" );
BOOST_CHECK( c.empty() );
BOOST_CHECK_EQUAL( c.description(), "copied" );
}
BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor, T, seq_type)
{
T s;
s.description("moved");
T m(std::move(s));
BOOST_CHECK( s.empty() );
BOOST_CHECK( s.description().empty() );
BOOST_CHECK( m.empty() );
BOOST_CHECK_EQUAL( m.description(), "moved" );
}
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor_nodscr, T, seqnd_type)
{
T s;
T c(s);
BOOST_CHECK( s.empty() );
BOOST_CHECK( c.empty() );
}
BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor_noname, T, seqnd_type)
{
T s;
T m(std::move(s));
BOOST_CHECK( s.empty() );
BOOST_CHECK( m.empty() );
}
Supports Markdown
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