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

add move constructor for sequence_host class with unit tests

parent 6a96c61a
......@@ -66,15 +66,20 @@ public:
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
: ContainerT<CharT, AllocatorT<CharT>>(other)
{
copy_name(other, has_name_component<self_type>());
// std::cout << "copy called" << std::endl;
copy_name(other, has_name_component<self_type>());
}
sequence_host(
sequence_host&& other)
: ContainerT<CharT, AllocatorT<CharT>>(other)
{}
// { std::cout << "move called" << std::endl; }
sequence_host&& other
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
: ContainerT<CharT, AllocatorT<CharT>>(std::forward<sequence_host>(other))
{
// std::cout << "move called" << std::endl;
move_name(
std::forward<sequence_host>(other)
, has_name_component<self_type>() );
}
sequence_host(
std::initializer_list<CharT> init
......@@ -87,6 +92,11 @@ public:
{ self_type::_name = other._name; }
void copy_name(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)
{}
};
//----------------------------------------------------------------------------//
......
......@@ -15,3 +15,4 @@ TACCGAGGTATTCTAATGGTGCTGCAACACTATCATGTAAAACAGCAAACTCTCTAAGTGCTTGGGAGAA
CCCTTCTTTATCGCCTTCTTCAGCAGCTTTTTCTAATACAGTAATGCGTATACGAAATTGTGCTTCGTAT
CCCTCCGTAC
......@@ -149,6 +149,16 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(read_multi_fasta, T, seq_types)
BOOST_CHECK_EQUAL(reads[2].name(), "gi|406593966|ref|NC_018627.1|-37467/1");
BOOST_CHECK_EQUAL(reads[3].name(), "gi|406593966|ref|NC_018627.1|-37467/2");
// T copy(reads[0]);
// BOOST_CHECK_EQUAL(copy.name(), "gi|406593966|ref|NC_018627.1|-40485/1");
// BOOST_CHECK_EQUAL(copy.data(), "ACACCAGAAGCATCGTCTGTTGTGGTGATATATGCGGGCTCTTCTGTTATCTCGTTAAGATCGAGATGGAGATTCTTTACTGAGATGTTGTTGGTAGTTTGAAACTTCGTCCCAGGATGCATGCAGAGTATAGATTGAAGATTTTCATCA");
// T move(std::move(reads[0]));
// BOOST_CHECK_EQUAL(move.data(), "ACACCAGAAGCATCGTCTGTTGTGGTGATATATGCGGGCTCTTCTGTTATCTCGTTAAGATCGAGATGGAGATTCTTTACTGAGATGTTGTTGGTAGTTTGAAACTTCGTCCCAGGATGCATGCAGAGTATAGATTGAAGATTTTCATCA");
// BOOST_CHECK_EQUAL(move.name(), "gi|406593966|ref|NC_018627.1|-40485/1");
// BOOST_CHECK( reads[0].empty() );
// BOOST_CHECK( reads[0].name().empty() );
// std::list<T> reads;
// std::copy(
// std::istream_iterator<T>(in)
......
......@@ -172,12 +172,28 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor, T, seq_types)
T seq("ATCG");
T copy(seq);
BOOST_CHECK_EQUAL(copy.size(), 4);
auto b = copy.cbegin();
BOOST_CHECK_EQUAL( *b , 'A');
BOOST_CHECK_EQUAL(*(++b), 'T');
BOOST_CHECK_EQUAL(*(++b), 'C');
BOOST_CHECK_EQUAL(*(++b), 'G');
BOOST_CHECK_EQUAL(seq.size(), 4);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor, T, seq_types)
{
T seq("ATCG");
T moved(std::move(seq));
BOOST_CHECK( seq.empty() );
BOOST_CHECK_EQUAL(moved.size(), 4);
auto b = moved.cbegin();
BOOST_CHECK_EQUAL( *b , 'A');
BOOST_CHECK_EQUAL(*(++b), 'T');
BOOST_CHECK_EQUAL(*(++b), 'C');
BOOST_CHECK_EQUAL(*(++b), 'G');
}
BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_initializer_list, T, seq_types)
......
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