Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "cppunit/extensions/HelperMacros.h"
0002 #include <algorithm>
0003 #include <iterator>
0004 #include <iostream>
0005 #include "DataFormats/Common/interface/AssociationMap.h"
0006 
0007 class testOneToManyAssociation : public CppUnit::TestFixture {
0008   CPPUNIT_TEST_SUITE(testOneToManyAssociation);
0009   CPPUNIT_TEST(checkAll);
0010   CPPUNIT_TEST_SUITE_END();
0011 
0012 public:
0013   void setUp() {}
0014   void tearDown() {}
0015   void checkAll();
0016   void dummy();
0017 };
0018 
0019 CPPUNIT_TEST_SUITE_REGISTRATION(testOneToManyAssociation);
0020 
0021 void testOneToManyAssociation::checkAll() {
0022   typedef std::vector<int> CKey;
0023   typedef std::vector<double> CVal;
0024   typedef edm::AssociationMap<edm::OneToMany<CKey, CVal, unsigned char> > Assoc;
0025   Assoc v;
0026   CPPUNIT_ASSERT(v.empty());
0027   CPPUNIT_ASSERT(v.size() == 0);
0028 }
0029 
0030 // just check that some stuff compiles
0031 void testOneToManyAssociation::dummy() {
0032   typedef std::vector<int> CKey;
0033   typedef std::vector<double> CVal;
0034   {
0035     typedef edm::AssociationMap<edm::OneToMany<CKey, CVal, unsigned char> > Assoc;
0036     Assoc v;
0037     v.insert(edm::Ref<CKey>(), edm::Ref<CVal>());
0038     v.insert(Assoc::value_type(edm::Ref<CKey>(), edm::RefVector<CVal>()));
0039     Assoc::const_iterator b = v.begin(), e = v.end();
0040     ++b;
0041     ++e;
0042     Assoc::const_iterator f = v.find(edm::Ref<CKey>());
0043     v.numberOfAssociations(edm::Ref<CKey>());
0044     const edm::RefVector<CVal>& x = v[edm::Ref<CKey>()];
0045     x.size();
0046     ++f;
0047     int n = v.numberOfAssociations(edm::Ref<CKey>());
0048     ++n;
0049     edm::Ref<Assoc> r;
0050     v[edm::Ref<CKey>()];
0051     v.erase(edm::Ref<CKey>());
0052     v.clear();
0053     CPPUNIT_ASSERT(v.size() == 0);
0054     v.post_insert();
0055   }
0056   {
0057     typedef edm::AssociationMap<edm::OneToManyWithQuality<CKey, CVal, double, unsigned char> > Assoc;
0058     Assoc v;
0059     v.insert(edm::Ref<CKey>(), std::make_pair(edm::Ref<CVal>(), 3.14));
0060     Assoc::const_iterator b = v.begin(), e = v.end();
0061     ++b;
0062     ++e;
0063     Assoc::const_iterator f = v.find(edm::Ref<CKey>());
0064     v.numberOfAssociations(edm::Ref<CKey>());
0065     const std::vector<std::pair<edm::Ref<CVal>, double> >& x = v[edm::Ref<CKey>()];
0066     x.size();
0067     ++f;
0068     int n = v.numberOfAssociations(edm::Ref<CKey>());
0069     ++n;
0070     edm::Ref<Assoc> r;
0071     v[edm::Ref<CKey>()];
0072     v.erase(edm::Ref<CKey>());
0073     v.clear();
0074     CPPUNIT_ASSERT(v.size() == 0);
0075     v.post_insert();
0076   }
0077 }