source: trunk/test/test_vector.cc @ 257

Last change on this file since 257 was 257, checked in by Jari Häkkinen, 17 years ago

Added vector views and made vector member functions to be non-member functions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.2 KB
Line 
1// $Id: test_vector.cc 257 2005-03-04 00:53:34Z jari $
2
3#include "vector.h"
4
5int main(const int argc,const char* argv[])
6{ 
7  bool ok = true;
8
9  theplu::gslapi::vector vec(12);
10  for (unsigned int i=0; i<vec.size(); i++) 
11    vec(i)=i;
12
13  // checking that shuffle works
14  double sum_before = vec.sum();
15  vec.shuffle();
16  double sum_after = vec.sum();
17  if (sum_after != sum_before)
18    ok = false;
19
20  // checking that view works
21  sum_before=0;
22  for (unsigned int i=0; i<vec.size(); i+=2) 
23    sum_before+=vec[i];
24  theplu::gslapi::vector vec_view(vec,0,6,2);
25  sum_after=vec_view.sum();
26  if (sum_after != sum_before)
27    ok = false;
28  vec[0]=0;
29  vec_view[0]=24;
30  if (vec[0]!=vec_view[0])
31    ok=false;
32
33  // checking that copy contrutor creates an independent object
34  theplu::gslapi::vector vec2(vec);
35  if (vec.size()!=vec2.size())
36    ok=false;
37  if (&vec2 == &vec)
38    ok=false;
39  if (vec2.isview())
40    ok=false;
41
42  // checking that copy contrutor creates an independent object when
43  // copying a view
44  vec2=vec_view;
45  if (vec_view.size()!=vec2.size())
46    ok=false;
47  if ((&vec2 == &vec_view) || (&vec2 == &vec))
48    ok=false;
49  if (vec2.isview())
50    ok=false;
51  vec2[0]=0;
52  vec_view[0]=24;
53  if (vec2[0]==vec_view[0])
54    ok=false;
55
56  if (ok) {
57    std::cout << "test_vector: SUCCESS\n";
58    return 0;
59  }
60  std::cerr << "test_vector: FAILED\n";
61  return -1;
62}
Note: See TracBrowser for help on using the repository browser.