MapOfVectors_t.cpp
Go to the documentation of this file.
1 #include "canvas/test/CppUnit_testdriver.icpp"
2 #include <cppunit/extensions/HelperMacros.h>
3 
4 #define private public
5 #include "art/Persistency/Common/MapOfVectors.h"
6 #undef private
7 
9 
10 #include <algorithm>
11 #include <vector>
12 
13 typedef art::MapOfVectors<int,int> MII;
15 
16 class TestMapOfVectors: public CppUnit::TestFixture
17 {
23 
24 
26 
27 public:
28 
31  void setUp() {}
32  void tearDown() {}
33 
34  void default_ctor();
35  void filling();
36  void find();
37  void iterator();
38 
40  unsigned int tot;
41 public:
42 
43 };
44 
46 
48  int v[10] = {0,1,2,3,4,5,6,7,8,9};
49  tot=0;
50  for (int i=0;i<10;++i) {
51  tot+=i;
52  om[i].resize(i);
53  std::copy(v,v+i,om[i].begin());
54  }
55 
56 }
57 
59 
60 
62  MII m;
63  CPPUNIT_ASSERT(m.size()==0);
64  CPPUNIT_ASSERT(m.empty());
65  CPPUNIT_ASSERT(m.m_keys.size()==0);
66  CPPUNIT_ASSERT(m.m_offsets.size()==1);
67  CPPUNIT_ASSERT(m.m_offsets[0]==0);
68  CPPUNIT_ASSERT(m.m_data.size()==0);
69 
70 }
71 
73  MII m(om);
74  CPPUNIT_ASSERT(m.size()==om.size());
75  CPPUNIT_ASSERT(!m.empty());
76  CPPUNIT_ASSERT(m.m_keys.size()==om.size());
77  CPPUNIT_ASSERT(m.m_offsets.size()==om.size()+1);
78  CPPUNIT_ASSERT(m.m_offsets[0]==0);
79  CPPUNIT_ASSERT(m.m_offsets[m.size()]==tot);
80  CPPUNIT_ASSERT(m.m_data.size()==tot);
81 }
82 
84  MII m(om);
85  CPPUNIT_ASSERT(m.find(-1)==m.emptyRange());
86  for(TheMap::const_iterator p=om.begin(); p!=om.end();++p) {
87  MII::range r = m.find((*p).first);
88  CPPUNIT_ASSERT(int(r.size())==(*p).first);
89  CPPUNIT_ASSERT(std::equal((*p).second.begin(), (*p).second.end(),r.begin()));
90  }
91 }
92 
94  MII m(om);
95  TheMap::const_iterator op=om.begin();
96  unsigned int lt=0;
97  for(MII::const_iterator p=m.begin(); p!=m.end();++p) {
98  CPPUNIT_ASSERT((*p).first==(*op).first);
99  CPPUNIT_ASSERT(std::equal((*p).second.begin(), (*p).second.end(),(*op).second.begin()));
100  lt+=(*p).second.size();
101  ++op;
102  }
103  CPPUNIT_ASSERT(lt==tot);
104 }
static const double m
Definition: Units.h:79
CPPUNIT_TEST_SUITE(TestMapOfVectors)
intermediate_table::iterator iterator
CPPUNIT_TEST_SUITE_REGISTRATION(TestMapOfVectors)
unsigned int tot
art::MapOfVectors< int, int > MII
intermediate_table::const_iterator const_iterator
auto begin(Data< Value > const &data)
MII::TheMap TheMap
T copy(T const &v)
CPPUNIT_TEST(default_ctor)