Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:43

0001 #include <vector>
0002 #include <algorithm>
0003 #include <memory>
0004 #include "TrackingTools/PatternTools/interface/bqueue.h"
0005 #include <iostream>
0006 #include <cassert>
0007 
0008 typedef cmsutils::bqueue<std::unique_ptr<int>> Cont;
0009 
0010 inline void verifySeq(Cont const& cont, int incr = 0) {
0011   int n = cont.size();
0012   for (auto const& item : cont) {
0013     assert((*item) - incr == --n);
0014   }
0015   assert(n == 0);
0016 }
0017 
0018 int main() {
0019   Cont cont, cont1, cont2;
0020   assert(cont.size() == 0);
0021   verifySeq(cont);
0022   assert(cont.begin() == cont.end());
0023 
0024   constexpr int v[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
0025   constexpr int v1[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
0026   constexpr int N = sizeof(v) / sizeof(int);
0027   constexpr int N1 = sizeof(v1) / sizeof(int);
0028 
0029   for (auto i : v)
0030     cont.push_back(Cont::value_type(new int(i)));
0031   for (auto i : v)
0032     cont1.emplace_back(new int(i));
0033   for (auto i : v1)
0034     cont2.emplace_back(new int(i));
0035 
0036   assert(cont.size() == N);
0037   assert(cont1.size() == N);
0038   assert(cont2.size() == N1);
0039   verifySeq(cont);
0040   verifySeq(cont1);
0041   verifySeq(cont2, 10);
0042 
0043   // copy
0044   assert(!cont.shared());
0045   Cont cont3(cont);
0046   assert(cont.size() == cont3.size());
0047   assert(cont.shared());
0048   assert(cont3.shared());
0049   verifySeq(cont3);
0050   // copy assign
0051   {
0052     Cont cont_assign;
0053     cont_assign = cont;
0054     assert(cont.size() == cont_assign.size());
0055     assert(cont.shared());
0056     assert(cont_assign.shared());
0057     verifySeq(cont_assign);
0058   }
0059   // add
0060   cont.push_back(Cont::value_type(new int(10)));
0061   assert((*cont.back()) == 10);
0062   assert((*cont3.back()) == 9);
0063   assert(cont.shared());
0064   assert(cont3.shared());
0065   verifySeq(cont);
0066   cont3.clear();
0067   assert(!cont.shared());
0068   assert(cont.size() == N + 1);
0069   verifySeq(cont);
0070 
0071   // join
0072   cont1.join(cont2);
0073   assert(cont1.size() == N + N1);
0074   assert(cont2.size() == 0);
0075   assert(cont2.begin() == cont2.end());
0076   verifySeq(cont1);
0077   verifySeq(cont2);
0078   assert(!cont1.shared());
0079   // add
0080   cont1.push_back(Cont::value_type(new int(20)));
0081   assert((*cont1.back()) == 20);
0082   verifySeq(cont1);
0083 
0084   Cont h, t1;
0085   for (auto i : v)
0086     h.emplace_back(new int(i));
0087   for (auto i : v1)
0088     t1.emplace_back(new int(i));
0089   Cont t2(t1);
0090   assert(!h.shared());
0091   assert(t1.shared());
0092   assert(t2.shared());
0093   // h.join(t1); //  bombs..
0094   t2.clear();
0095 
0096   cont.clear();
0097   assert(cont.size() == 0);
0098   verifySeq(cont);
0099   assert(cont.begin() == cont.end());
0100 
0101   return cont.size();
0102 }