File: test_vector.cxx

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,652 kB
  • sloc: cpp: 458,133; ansic: 196,223; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 430; csh: 220; perl: 193; xml: 20
file content (72 lines) | stat: -rw-r--r-- 1,730 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// This is vcl/tests/test_vector.cxx
#include <vcl_iostream.h>
#include <vcl_vector.h>
#include <vcl_algorithm.h>

vcl_ostream &delim(vcl_ostream &os)
{
  //return os << endl;
  return os << ", ";
}

int frurk(vcl_vector<int> const &a,
          vcl_vector<int> const &b)
{
  if (a == b)
    return 0;
  if (a != b)
    return 1;
  return 2;
}

int test_vector_main(int /*argc*/,char* /*argv*/[])
{
  bool fail = false;
  {
    typedef vcl_vector<int> container;
    container m;

    m.push_back(1);
    m.push_back(2);

    for (container::iterator p = m.begin(); p != m.end(); ++p)
      vcl_cout << (*p) << vcl_endl;
  }
  {
    vcl_vector<double> v;
    for (unsigned i=0; i<10; ++i)
    {
      vcl_cout << "size : " << v.size() << delim
               << "capacity : " << v.capacity() << delim;
      if (i>0)
        vcl_cout << "begin : " << (void*) &* v.begin()
                 << delim << "end - 1: " << (void*) &* (v.end() - 1) << vcl_endl;
      else
        vcl_cout << vcl_endl;

      v.push_back(13.141592653589793 * i);
    }
  }
  {
      vcl_vector<bool> bv(2);
      bv[0] = true;
      bv[1] = false;
      vcl_nth_element(bv.begin(), bv.begin()+1, bv.end());
  }
  { // check contiguity
#define macro(T) do { \
    vcl_vector<T > v; \
    for (int i=0; i<5; ++i) v.push_back(T(i)); \
    bool ok = true; \
    for (unsigned int i=1; i<v.size(); ++i) { T *p = &v[i-1]; T *q = &v[i]; if (p + 1 != q) ok = false; } \
    if (ok) vcl_cout << "PASS: vector<" << #T << "> has contiguous storage\n"; \
    else  { vcl_cout << "FAIL: vector<" << #T << "> has non-contiguous storage\n"; fail = true; } \
} while (false)
    macro(char);
    macro(int);
    macro(double);
#undef macro
  }

  return fail ? 1 : 0;
}