libsequence  1.9.5
CountingOperators.cc
2 #include <boost/test/unit_test.hpp>
3 #include <algorithm>
4 #include <functional>
5 #include <string>
6 
7 BOOST_AUTO_TEST_SUITE(CountingOperatorsTest)
8 
9 BOOST_AUTO_TEST_CASE( test_counting_operators_map_plus )
10 {
11  using Sequence::operator+;
12  std::map<char,unsigned> baseCounts,baseCounts2;
13  baseCounts['A'] = 5;
14  baseCounts['G'] = 10;
15  baseCounts2['A'] = 11;
16  baseCounts2['C'] = 17;
17  std::map<char,unsigned> baseCounts3 = baseCounts + baseCounts2;
18 
19  BOOST_REQUIRE_EQUAL( baseCounts3['A'], 16 );
20  BOOST_REQUIRE_EQUAL( baseCounts3['G'], 10 );
21  BOOST_REQUIRE_EQUAL( baseCounts3['C'], 17 );
22 }
23 
24 BOOST_AUTO_TEST_CASE( test_counting_operators_map_plus_equal )
25 {
26  using Sequence::operator+=;
27  std::map<char,unsigned> baseCounts,baseCounts2;
28  baseCounts['A'] = 5;
29  baseCounts['G'] = 10;
30  baseCounts2['A'] = 11;
31  baseCounts2['C'] = 17;
32  baseCounts += baseCounts2;
33 
34  BOOST_REQUIRE_EQUAL( baseCounts['A'], 16 );
35  BOOST_REQUIRE_EQUAL( baseCounts['G'], 10 );
36  BOOST_REQUIRE_EQUAL( baseCounts['C'], 17 );
37 }
38 
39 BOOST_AUTO_TEST_CASE( test_counting_operators_vector_plus )
40 {
41  using Sequence::operator+;
42  std::vector< std::pair<char,unsigned> > baseCounts,baseCounts2;
43  baseCounts.push_back(std::make_pair('A',5u));
44  baseCounts.push_back(std::make_pair('G',10u));
45  baseCounts2.push_back(std::make_pair('A',11u));
46  baseCounts2.push_back(std::make_pair('C',17u));
47 
48  auto baseCounts3 = baseCounts + baseCounts2;
49 
50  std::string bases = {'A','G','C'};
51 
52  auto i = std::find_if(baseCounts3.cbegin(),
53  baseCounts3.cend(),
54  [](const std::pair<char,unsigned> & __p) {
55  return __p.first == 'A';
56  });
57  BOOST_REQUIRE( i != baseCounts3.cend() );
58  BOOST_REQUIRE_EQUAL( i->second,16 );
59 
60  i = std::find_if(baseCounts3.cbegin(),
61  baseCounts3.cend(),
62  [](const std::pair<char,unsigned> & __p) {
63  return __p.first == 'G';
64  });
65  BOOST_REQUIRE( i != baseCounts3.cend() );
66  BOOST_REQUIRE_EQUAL( i->second,10 );
67 
68  i = std::find_if(baseCounts3.cbegin(),
69  baseCounts3.cend(),
70  [](const std::pair<char,unsigned> & __p) {
71  return __p.first == 'C';
72  });
73  BOOST_REQUIRE( i != baseCounts3.cend() );
74  BOOST_REQUIRE_EQUAL( i->second,17 );
75 
76 }
77 BOOST_AUTO_TEST_SUITE_END()
Declarations of operators to add associative containers together.