Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:06

0001 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0002 #include "cppunit/extensions/HelperMacros.h"
0003 
0004 #include "DataFormats/Common/interface/MapOfVectors.h"
0005 
0006 #include <vector>
0007 #include <algorithm>
0008 
0009 typedef edm::MapOfVectors<int, int> MII;
0010 typedef MII::TheMap TheMap;
0011 
0012 class TestMapOfVectors : public CppUnit::TestFixture {
0013   CPPUNIT_TEST_SUITE(TestMapOfVectors);
0014   CPPUNIT_TEST(default_ctor);
0015   CPPUNIT_TEST(filling);
0016   CPPUNIT_TEST(find);
0017   CPPUNIT_TEST(iterator);
0018 
0019   CPPUNIT_TEST_SUITE_END();
0020 
0021 public:
0022   TestMapOfVectors();
0023   ~TestMapOfVectors();
0024   void setUp() {}
0025   void tearDown() {}
0026 
0027   void default_ctor();
0028   void filling();
0029   void find();
0030   void iterator();
0031 
0032   TheMap om;
0033   unsigned int tot;
0034 
0035 public:
0036 };
0037 
0038 CPPUNIT_TEST_SUITE_REGISTRATION(TestMapOfVectors);
0039 
0040 TestMapOfVectors::TestMapOfVectors() {
0041   int v[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
0042   tot = 0;
0043   for (int i = 0; i < 10; ++i) {
0044     tot += i;
0045     om[i].resize(i);
0046     std::copy(v, v + i, om[i].begin());
0047   }
0048 }
0049 
0050 TestMapOfVectors::~TestMapOfVectors() {}
0051 
0052 void TestMapOfVectors::default_ctor() {
0053   MII m;
0054   CPPUNIT_ASSERT(m.size() == 0);
0055   CPPUNIT_ASSERT(m.empty());
0056   CPPUNIT_ASSERT(m.m_keys.size() == 0);
0057   CPPUNIT_ASSERT(m.m_offsets.size() == 1);
0058   CPPUNIT_ASSERT(m.m_offsets[0] == 0);
0059   CPPUNIT_ASSERT(m.m_data.size() == 0);
0060 }
0061 
0062 void TestMapOfVectors::filling() {
0063   MII m(om);
0064   CPPUNIT_ASSERT(m.size() == om.size());
0065   CPPUNIT_ASSERT(!m.empty());
0066   CPPUNIT_ASSERT(m.m_keys.size() == om.size());
0067   CPPUNIT_ASSERT(m.m_offsets.size() == om.size() + 1);
0068   CPPUNIT_ASSERT(m.m_offsets[0] == 0);
0069   CPPUNIT_ASSERT(m.m_offsets[m.size()] == tot);
0070   CPPUNIT_ASSERT(m.m_data.size() == tot);
0071 }
0072 
0073 void TestMapOfVectors::find() {
0074   MII m(om);
0075   CPPUNIT_ASSERT(m.find(-1) == m.emptyRange());
0076   for (TheMap::const_iterator p = om.begin(); p != om.end(); ++p) {
0077     MII::range r = m.find((*p).first);
0078     CPPUNIT_ASSERT(int(r.size()) == (*p).first);
0079     CPPUNIT_ASSERT(std::equal((*p).second.begin(), (*p).second.end(), r.begin()));
0080   }
0081 }
0082 
0083 void TestMapOfVectors::iterator() {
0084   MII m(om);
0085   TheMap::const_iterator op = om.begin();
0086   unsigned int lt = 0;
0087   for (MII::const_iterator p = m.begin(); p != m.end(); ++p) {
0088     CPPUNIT_ASSERT((*p).first == (*op).first);
0089     CPPUNIT_ASSERT(std::equal((*p).second.begin(), (*p).second.end(), (*op).second.begin()));
0090     lt += (*p).second.size();
0091     ++op;
0092   }
0093   CPPUNIT_ASSERT(lt == tot);
0094 }