Functions
test_set.cxx File Reference
#include "WireCellUtil/Testing.h"
#include <vector>
#include <set>
#include <deque>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <memory>
#include <random>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

int main ( void  )

Definition at line 18 of file test_set.cxx.

19 {
20  // http://stackoverflow.com/a/10604500
21  vector<int> items = {0,1,2,3,4,5,6,7,8,9};
22  set<int> die = {2,4,5,42};
23  set<int> die2;
24 
25  vector<int> result;
26  set_difference(items.begin(), items.end(),
27  die.begin(), die.end(),
28  back_inserter(result));
29  cout << "items: ";
30  for (auto item : items) {
31  cout << item << " ";
32  }
33  cout << endl;
34  cout << "alive: ";
35  for (auto alive: result) {
36  cout << alive << " ";
37  }
38  cout << endl;
39 
40  vector<int> result2;
41  set_difference(items.begin(), items.end(),
42  die2.begin(), die2.end(),
43  back_inserter(result2));
44 
45  Assert(items.size() == 10);
46  Assert(die.size() == 4);
47  Assert(result.size() == 7);
48 
49  Assert(die2.size() == 0);
50  Assert(result2.size() == 10);
51 
52  {
53  std::random_device rd;
54  std::default_random_engine re(rd());
55  std::uniform_real_distribution<> dist(0, 1000);
56 
57  typedef std::shared_ptr<int> Pint;
58  deque<Pint> queue;
59  const int nitems = 1000;
60  for (int ind=0; ind<nitems; ++ind) {
61  queue.push_back(Pint(new int(dist(re))));
62  }
63  for (int ind=0; ind<nitems; ++ind) {
64  Pint front = queue.front();
65  queue.pop_front();
66  cerr << ind << ": popped:" << *front
67  << " now with: " << queue.size() << " items"
68  << endl;
69  }
70  }
71 }
static QCString result
#define Assert
Definition: Testing.h:7
QTextStream & endl(QTextStream &s)