Exemple #1
0
void TestDetSet::inserting() {

  DSTV detsets(2);
  unsigned int ntot=0;
  for (unsigned int n=1;n<5;++n) {
    ntot+=n;
    unsigned int id=20+n;
    DST df = detsets.insert(id,n);
    CPPUNIT_ASSERT(detsets.size()==n);
    CPPUNIT_ASSERT(detsets.dataSize()==ntot);
    CPPUNIT_ASSERT(detsets.detsetSize(n-1)==n);
    CPPUNIT_ASSERT(df.size()==n);
    CPPUNIT_ASSERT(df.id()==id);

    std::copy(sv.begin(),sv.begin()+n,df.begin());

    std::vector<DST::data_type> v1(n);
    std::vector<DST::data_type> v2(n);
    std::copy(detsets.m_data.begin()+ntot-n,detsets.m_data.begin()+ntot,v2.begin());
    std::copy(sv.begin(),sv.begin()+n,v1.begin());
    CPPUNIT_ASSERT(v1==v2);
  }

  // test error conditions
  try {
    detsets.insert(22,6);
    CPPUNIT_ASSERT("insert did not throw"==0);
  }
  catch (edm::Exception const & err) {
    CPPUNIT_ASSERT(err.categoryCode()==edm::errors::InvalidReference);
  }
}
Exemple #2
0
void TestDetSet::onDemand() {
  auto pg = std::make_shared<Getter>(this);
  Getter & g = *pg;
  assert(!g.aborted);
  std::vector<unsigned int> v; v+= 21,23,25,27,1020;
  DSTV detsets(pg,v,2);
  CPPUNIT_ASSERT(g.ntot==0);
  CPPUNIT_ASSERT(detsets.onDemand());
  try {
    {
      CPPUNIT_ASSERT(detsets.exists(21));
      CPPUNIT_ASSERT(!detsets.exists(22));
      CPPUNIT_ASSERT(!detsets.isValid(21));
      CPPUNIT_ASSERT(!detsets.isValid(22));
      //      DST df = *detsets.find(21);
      detsets.reserve(5,100);
      DST df = *detsets.find(21,true);
      CPPUNIT_ASSERT(df.id()==21);
      CPPUNIT_ASSERT(df.size()==1);
      CPPUNIT_ASSERT(detsets.isValid(21));
      CPPUNIT_ASSERT(!detsets.isValid(23));
      CPPUNIT_ASSERT(g.ntot==1);
      assert(!g.aborted);
    }
    {
      DST df = detsets[25];
      CPPUNIT_ASSERT(df.id()==25);
      CPPUNIT_ASSERT(df.size()==5);
      CPPUNIT_ASSERT(g.ntot==1+5);
      assert(!g.aborted);
    }
    {
      DST df = detsets[1020];
      CPPUNIT_ASSERT(df.id()==1020);
      CPPUNIT_ASSERT(df.size()==0);
      CPPUNIT_ASSERT(g.ntot==1+5);
      assert(g.aborted);
    }

  }
  catch (edm::Exception const &) {
    CPPUNIT_ASSERT("DetSetVector threw when not expected"==0);
  }
  // no onDemand!
  int i=0;
  //  for (auto di = detsets.begin(false); di!=detsets.end(false); ++di) {
  for (auto di = detsets.begin(); di!=detsets.end(); ++di) {
    ++i;
    auto ds = *di;
    auto id = ds.id();
    CPPUNIT_ASSERT(id==1020 || (id>20&&id<28&& id%2==1));
    if (1020==id || 21==id || 25==id) CPPUNIT_ASSERT(ds.isValid());
    else CPPUNIT_ASSERT(!ds.isValid());
  }
  CPPUNIT_ASSERT(5==i);
  CPPUNIT_ASSERT(g.ntot==1+5);

  //  CPPUNIT_ASSERT(std::for_each(detsets.begin(),detsets.end(),VerifyIter(this,1,2)).n==9);
  CPPUNIT_ASSERT(std::for_each(detsets.begin(true),detsets.end(true),VerifyIter(this,1,2)).n==9);

  //  CPPUNIT_ASSERT(std::for_each(detsets.begin(),detsets.end(),VerifyIter(this,1,2)).n==9);
  CPPUNIT_ASSERT(std::for_each(detsets.begin(true),detsets.end(true),VerifyIter(this,1,2)).n==9);
  CPPUNIT_ASSERT(g.ntot==1+3+5+7);

  try{
    DSTV::const_iterator p = detsets.find(22);
    CPPUNIT_ASSERT(p==detsets.end());
  }
  catch (edm::Exception const &) {
    CPPUNIT_ASSERT("find thrown edm exception when not expected"==0);

  }
  try{
    detsets[22];
    CPPUNIT_ASSERT("[] did not throw"==0);
  }
  catch (edm::Exception const & err) {
       CPPUNIT_ASSERT(err.categoryCode()==edm::errors::InvalidReference);
  }

  DSTV detsets2;
  detsets2.swap(detsets);
  CPPUNIT_ASSERT(detsets2.onDemand());

  DSTV detsets3;
  detsets3 = std::move(detsets2);
  CPPUNIT_ASSERT(detsets3.onDemand());
  DSTV detsets5(std::move(detsets3));
  CPPUNIT_ASSERT(detsets5.onDemand());

  DSTV detsets4(detsets5);
  CPPUNIT_ASSERT(detsets4.onDemand());
}
Exemple #3
0
void TestDetSet::iterator() {
  DSTV detsets(2);
  for (unsigned int n=1;n<5;++n) {
    unsigned int id=20+n;
    FF ff(detsets,id);
    ff.resize(n);
    std::copy(sv.begin(),sv.begin()+n,ff.begin());
  }
  //  CPPUNIT_ASSERT(std::for_each(detsets.begin(),detsets.end(),VerifyIter(this)).n==5);
  CPPUNIT_ASSERT(std::for_each(detsets.begin(true),detsets.end(true),VerifyIter(this)).n==5);
  {
    FF ff(detsets,31);
    ff.resize(2);
    std::copy(sv.begin(),sv.begin()+2,ff.begin());
  }
  {
    FF ff(detsets,11);
    ff.resize(2);
    std::copy(sv.begin(),sv.begin()+2,ff.begin());
  }
  {
    FF ff(detsets,34);
    ff.resize(4);
    std::copy(sv.begin(),sv.begin()+4,ff.begin());
  }

  DSTV::Range r = detsets.equal_range(30,cmp10());
  CPPUNIT_ASSERT(r.second-r.first==2);
  r = detsets.equal_range(40,cmp10());
  CPPUNIT_ASSERT(r.second-r.first==0);

  try {
    {
      CPPUNIT_ASSERT(detsets.exists(22));
      CPPUNIT_ASSERT(!detsets.exists(44));
      DST df = *detsets.find(22);
      //      DST df = *detsets.find(22,true);
      CPPUNIT_ASSERT(df.id()==22);
      CPPUNIT_ASSERT(df.size()==2);
    }
    {
      DST df = detsets[22];
      CPPUNIT_ASSERT(df.id()==22);
      CPPUNIT_ASSERT(df.size()==2);
    }
  }
  catch (edm::Exception const &) {
    CPPUNIT_ASSERT("DetSetVector threw when not expected"==0);
  }

  try{
    DSTV::const_iterator p = detsets.find(44);
    //    DSTV::const_iterator p = detsets.find(44,true);
    CPPUNIT_ASSERT(p==detsets.end());
    //    CPPUNIT_ASSERT(p==detsets.end(true));
  }
  catch (edm::Exception const &) {
    CPPUNIT_ASSERT("find thrown edm exception when not expected"==0);

  }
  try{
    detsets[44];
    CPPUNIT_ASSERT("[] did not throw"==0);
  }
  catch (edm::Exception const & err) {
       CPPUNIT_ASSERT(err.categoryCode()==edm::errors::InvalidReference);
  }

 

}