Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "cppunit/extensions/HelperMacros.h"
0002 #include "DataFormats/Common/interface/IDVectorMap.h"
0003 #include "DataFormats/Common/interface/CopyPolicy.h"
0004 
0005 class testIDVectorMap : public CppUnit::TestFixture {
0006   CPPUNIT_TEST_SUITE(testIDVectorMap);
0007   CPPUNIT_TEST(checkAll);
0008   CPPUNIT_TEST_SUITE_END();
0009 
0010 public:
0011   void setUp() {}
0012   void tearDown() {}
0013   void checkAll();
0014 };
0015 
0016 CPPUNIT_TEST_SUITE_REGISTRATION(testIDVectorMap);
0017 
0018 #include <iostream>
0019 
0020 struct MatchOddId {
0021   bool operator()(int i) const { return i % 2 == 1; }
0022 };
0023 
0024 void testIDVectorMap::checkAll() {
0025   typedef edm::IDVectorMap<int, std::vector<int>, edm::CopyPolicy<int> > map;
0026   map m;
0027   int v1[] = {1, 2, 3, 4};
0028   int v2[] = {5, 6, 7};
0029   int v3[] = {8, 9};
0030   int s1 = sizeof(v1) / sizeof(int);
0031   int s2 = sizeof(v2) / sizeof(int);
0032   int s3 = sizeof(v3) / sizeof(int);
0033   for (int i = 0; i < s1; ++i)
0034     m.insert(1, v1[i]);
0035   //  for(int i = 0; i < s2; ++i) m.insert(2, v2[i]);
0036   m.insert(2, v2, v2 + s2);
0037   for (int i = 0; i < s3; ++i)
0038     m.insert(3, v3[i]);
0039 
0040   map::const_iterator i = m.begin();
0041   CPPUNIT_ASSERT(*i++ == 1);
0042   CPPUNIT_ASSERT(*i++ == 2);
0043   CPPUNIT_ASSERT(*i++ == 3);
0044   CPPUNIT_ASSERT(*i++ == 4);
0045   CPPUNIT_ASSERT(*i++ == 5);
0046   CPPUNIT_ASSERT(*i++ == 6);
0047   CPPUNIT_ASSERT(*i++ == 7);
0048   CPPUNIT_ASSERT(*i++ == 8);
0049   CPPUNIT_ASSERT(*i++ == 9);
0050   CPPUNIT_ASSERT(i == m.end());
0051 
0052   CPPUNIT_ASSERT(*--i == 9);
0053   CPPUNIT_ASSERT(*--i == 8);
0054   CPPUNIT_ASSERT(*--i == 7);
0055   CPPUNIT_ASSERT(*--i == 6);
0056   CPPUNIT_ASSERT(*--i == 5);
0057   CPPUNIT_ASSERT(*--i == 4);
0058   CPPUNIT_ASSERT(*--i == 3);
0059   CPPUNIT_ASSERT(*--i == 2);
0060   CPPUNIT_ASSERT(*--i == 1);
0061   CPPUNIT_ASSERT(i == m.begin());
0062 
0063   map::id_iterator b = m.id_begin();
0064   CPPUNIT_ASSERT(m.id_size() == 3);
0065   CPPUNIT_ASSERT(*b++ == 1);
0066   CPPUNIT_ASSERT(*b++ == 2);
0067   CPPUNIT_ASSERT(*b++ == 3);
0068   CPPUNIT_ASSERT(b == m.id_end());
0069 
0070   CPPUNIT_ASSERT(*--b == 3);
0071   CPPUNIT_ASSERT(*--b == 2);
0072   CPPUNIT_ASSERT(*--b == 1);
0073   CPPUNIT_ASSERT(b == m.id_begin());
0074 
0075   map::range r = m.get(1);
0076   CPPUNIT_ASSERT(r.end - r.begin == s1);
0077   map::container_iterator j = r.begin;
0078   CPPUNIT_ASSERT(*j++ == 1);
0079   CPPUNIT_ASSERT(*j++ == 2);
0080   CPPUNIT_ASSERT(*j++ == 3);
0081   CPPUNIT_ASSERT(*j++ == 4);
0082   CPPUNIT_ASSERT(j == r.end);
0083 
0084   MatchOddId o;
0085   map::match_iterator<MatchOddId> t = m.begin(o);
0086   CPPUNIT_ASSERT(*t++ == 1);
0087   CPPUNIT_ASSERT(*t++ == 2);
0088   CPPUNIT_ASSERT(*t++ == 3);
0089   CPPUNIT_ASSERT(*t++ == 4);
0090   CPPUNIT_ASSERT(*t++ == 8);
0091   CPPUNIT_ASSERT(*t++ == 9);
0092   CPPUNIT_ASSERT(t == m.end(o));
0093 
0094   /*
0095   m.put(1, v1, v1 + s1);
0096   m.put(2, v2, v2 + s2);
0097   m.put(3, v3, v3 + s3);
0098   map::range r1 = m.get(1);
0099   map::range r2 = m.get(2);
0100   map::range r3 = m.get(3);
0101   map::const_iterator i;
0102 
0103   CPPUNIT_ASSERT(r1.second - r1.first == s1);
0104   i = r1.first;
0105   CPPUNIT_ASSERT(*i++ == v1[ 0 ]);
0106   CPPUNIT_ASSERT(*i++ == v1[ 1 ]);
0107   CPPUNIT_ASSERT(*i++ == v1[ 2 ]);
0108   CPPUNIT_ASSERT(*i++ == v1[ 3 ]);
0109   CPPUNIT_ASSERT(i == r1.second);
0110 
0111   CPPUNIT_ASSERT(r2.second - r2.first == s2);
0112   i = r2.first;
0113   CPPUNIT_ASSERT(*i++ == v2[ 0 ]);
0114   CPPUNIT_ASSERT(*i++ == v2[ 1 ]);
0115   CPPUNIT_ASSERT(*i++ == v2[ 2 ]);
0116   CPPUNIT_ASSERT(i == r2.second);
0117 
0118   CPPUNIT_ASSERT(r3.second - r3.first == s3);
0119   i = r3.first;
0120   CPPUNIT_ASSERT(*i++ == v3[ 0 ]);
0121   CPPUNIT_ASSERT(*i++ == v3[ 1 ]);
0122   CPPUNIT_ASSERT(i == r3.second);
0123 
0124   CPPUNIT_ASSERT(m.size() == size_t(s1 + s2 + s3));
0125 
0126 
0127   */
0128 }