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 <algorithm>
0003 #include <iterator>
0004 #include <iostream>
0005 #include "DataFormats/Common/interface/AssociationVector.h"
0006 #include "DataFormats/Common/interface/TestHandle.h"
0007 using namespace edm;
0008 
0009 class testAssociationVector : public CppUnit::TestFixture {
0010   CPPUNIT_TEST_SUITE(testAssociationVector);
0011   CPPUNIT_TEST(checkAll);
0012   CPPUNIT_TEST_SUITE_END();
0013 
0014 public:
0015   void setUp() {}
0016   void tearDown() {}
0017   void checkAll();
0018 };
0019 
0020 CPPUNIT_TEST_SUITE_REGISTRATION(testAssociationVector);
0021 
0022 void testAssociationVector::checkAll() {
0023   typedef std::vector<double> CKey;
0024   typedef std::vector<int> CVal;
0025 
0026   CKey k;
0027   k.push_back(1.1);
0028   k.push_back(2.2);
0029   k.push_back(3.3);
0030   ProductID const pid(1, 1);
0031   TestHandle<CKey> handle(&k, pid);
0032   RefProd<CKey> ref(handle);
0033   AssociationVector<RefProd<CKey>, CVal> v(ref);
0034   v.setValue(0, 1);
0035   v.setValue(1, 2);
0036   v.setValue(2, 3);
0037   CPPUNIT_ASSERT(v.size() == 3);
0038   CPPUNIT_ASSERT(v.keyProduct() == ref);
0039   CPPUNIT_ASSERT(v[0].second == 1);
0040   CPPUNIT_ASSERT(v[1].second == 2);
0041   CPPUNIT_ASSERT(v[2].second == 3);
0042   CPPUNIT_ASSERT(*v[0].first == 1.1);
0043   CPPUNIT_ASSERT(*v[1].first == 2.2);
0044   CPPUNIT_ASSERT(*v[2].first == 3.3);
0045   CPPUNIT_ASSERT(*v.key(0) == 1.1);
0046   CPPUNIT_ASSERT(*v.key(1) == 2.2);
0047   CPPUNIT_ASSERT(*v.key(2) == 3.3);
0048   Ref<CKey> rc0(handle, 0), rc1(handle, 1), rc2(handle, 2);
0049   CPPUNIT_ASSERT(v[rc0] == 1);
0050   CPPUNIT_ASSERT(v[rc1] == 2);
0051   CPPUNIT_ASSERT(v[rc2] == 3);
0052   ProductID const assocPid(1, 2);
0053   TestHandle<AssociationVector<RefProd<CKey>, CVal> > assocHandle(&v, assocPid);
0054   Ref<AssociationVector<RefProd<CKey>, CVal> > r1(assocHandle, 0);
0055   CPPUNIT_ASSERT(*r1->first == 1.1);
0056   CPPUNIT_ASSERT(r1->second == 1);
0057   Ref<AssociationVector<RefProd<CKey>, CVal> > r2(assocHandle, 1);
0058   CPPUNIT_ASSERT(*r2->first == 2.2);
0059   CPPUNIT_ASSERT(r2->second == 2);
0060   Ref<AssociationVector<RefProd<CKey>, CVal> > r3(assocHandle, 2);
0061   CPPUNIT_ASSERT(*r3->first == 3.3);
0062   CPPUNIT_ASSERT(r3->second == 3);
0063   v[rc0] = 111;
0064   v[rc1] = 122;
0065   v[rc2] = 133;
0066   CPPUNIT_ASSERT(v[rc0] == 111);
0067   CPPUNIT_ASSERT(v[rc1] == 122);
0068   CPPUNIT_ASSERT(v[rc2] == 133);
0069 }