File: TestVectorOperators.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 118,532 kB
  • ctags: 138,251
  • sloc: cpp: 1,443,749; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,127; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 471; makefile: 95; objc: 17
file content (117 lines) | stat: -rw-r--r-- 3,529 bytes parent folder | download | duplicates (9)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestVector.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkSetGet.h"
#include "vtkVector.h"
#include "vtkVectorOperators.h"

//----------------------------------------------------------------------------
int TestVectorOperators(int, char*[])
{
  vtkVector3i vec3i(0, 6, 9);

  // Store up any errors, return non-zero if something fails.
  int retVal = 0;

  // Test out vtkVector3i and ensure the ostream operator is working.
  cout << "vec3i -> " << vec3i << endl;

  // Test the equality operator.
  vtkVector3i vec3ia(0, 6, 9);
  vtkVector3i vec3ib(0, 6, 8);
  vtkVector<int, 3> vector3f(vec3i.GetData());
  vector3f[0] = vector3f[2] = 6;
  if (!(vec3i == vec3ia))
    {
    cerr << "vec3i == vec3ia failed (are equal, but reported not)." << endl
         << "vec3i = " << vec3i << ", vec3ia = " << vec3ia << endl;
    ++retVal;
    }
  if (vec3ia == vec3ib)
    {
    cerr << "vec3ia == vec3ib failed (are not equal, but reported equal)."
         << endl << "vec3i = " << vec3i << ", vec3ia = " << vec3ia << endl;
    ++retVal;
    }
  if (vector3f == vec3i)
    {
    cerr << "vector3f == vec3ib failed (are not equal, but reported equal)."
         << endl << "vec3i = " << vector3f << ", vec3ia = " << vec3ia << endl;
    ++retVal;
    }

  // Test the inequality operator.
  if (vec3i != vec3ia)
    {
    cerr << "vec3i != vec3ia (reported as not equal, but are equal)." << endl
         << "vec3i = " << vec3i << ", vec3ia = " << vec3ia << endl;
    ++retVal;
    }

  // Does the + operator work as expected???
  vtkVector3i result = vec3ia + vec3ib;
  if (result != vtkVector3i(0, 12, 17))
    {
    cerr << "Vector addition operator failed." << endl;
    cerr << vec3ia << " + " << vec3ib << " = " << result << endl;
    ++retVal;
    }

  // Test the - operator.
  result = vec3ia - vec3ib;
  if (result != vtkVector3i(0, 0, 1))
    {
    cerr << "Vector subtraction operator failed." << endl;
    cerr << vec3ia << " - " << vec3ib << " = " << result << endl;
    ++retVal;
    }

  // Test the * operator.
  result = vec3ia * vec3ib;
  if (result != vtkVector3i(0, 36, 72))
    {
    cerr << "Vector multiplication operator failed." << endl;
    cerr << vec3ia << " * " << vec3ib << " = " << result << endl;
    ++retVal;
    }

  // Test the / operator.
  vec3i.SetX(1);
  result = vec3ia / vec3i;
  if (result != vtkVector3i(0, 1, 1))
    {
    cerr << "Vector division operator failed." << endl;
    cerr << vec3ia << " / " << vec3i << " = " << result << endl;
    ++retVal;
    }

  // Test the * operator with a scalar.
  result = vec3ia * 2;
  if (result != vtkVector3i(0, 12, 18))
    {
    cerr << "Vector multiplication by scalar operator failed." << endl;
    cerr << vec3ia << " * 2 = " << result << endl;
    ++retVal;
    }
  result = 2 * vec3ia;
  if (result != vtkVector3i(0, 12, 18))
    {
    cerr << "Vector multiplication by scalar operator failed." << endl;
    cerr << "2 * " << vec3ia << " = " << result << endl;
    ++retVal;
    }

  return retVal;
}