TestArrayExtents.cxx 2.75 KB
Newer Older
1
2
3
/*=========================================================================

  Program:   Visualization Toolkit
4
  Module:    ArrayExtents.cxx
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------

  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.

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

22
#include <vtkArrayCoordinates.h>
23
#include <vtkArrayExtents.h>
24
25
26
27

#include <vtksys/ios/iostream>
#include <vtksys/ios/sstream>
#include <vtksys/stl/stdexcept>
Francois Bertel's avatar
Francois Bertel committed
28
#include "vtkSetGet.h"
29
30
31
32
33

#define test_expression(expression) \
{ \
  if(!(expression)) \
    { \
34
    vtksys_ios::ostringstream buffer; \
35
36
37
38
39
    buffer << "Expression failed at line " << __LINE__ << ": " << #expression; \
    throw vtkstd::runtime_error(buffer.str()); \
    } \
}

40
int TestArrayExtents(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
41
42
43
{
  try
    {
44
    vtkArrayExtents slice(vtkArrayRange(2, 4), vtkArrayRange(6, 9));
45
46

    test_expression(slice.GetDimensions() == 2);
47
48
49
    test_expression(slice[0].GetSize() == 2);
    test_expression(slice[1].GetSize() == 3);
    test_expression(slice.GetSize() == 6);
50

51
    vtkArrayCoordinates coordinates;
52
    for(vtkIdType n = 0; n != slice.GetSize(); ++n)
53
      {
54
      slice.GetLeftToRightCoordinatesN(n, coordinates);
55
56
      cerr << coordinates << endl;
      }
57

58
    slice.GetLeftToRightCoordinatesN(0, coordinates);
59
    test_expression(coordinates == vtkArrayCoordinates(2, 6));
60
    slice.GetLeftToRightCoordinatesN(1, coordinates);
61
    test_expression(coordinates == vtkArrayCoordinates(3, 6));
62
    slice.GetLeftToRightCoordinatesN(2, coordinates);
63
    test_expression(coordinates == vtkArrayCoordinates(2, 7));
64
    slice.GetLeftToRightCoordinatesN(3, coordinates);
65
    test_expression(coordinates == vtkArrayCoordinates(3, 7));
66
    slice.GetLeftToRightCoordinatesN(4, coordinates);
67
    test_expression(coordinates == vtkArrayCoordinates(2, 8));
68
    slice.GetLeftToRightCoordinatesN(5, coordinates);
69
    test_expression(coordinates == vtkArrayCoordinates(3, 8));
70

71
72
73
    test_expression(slice.Contains(vtkArrayCoordinates(3, 7)));
    test_expression(!slice.Contains(vtkArrayCoordinates(1, 7)));

74
75
76
77
78
79
80
81
    return 0;
    }
  catch(vtkstd::exception& e)
    {
    cerr << e.what() << endl;
    return 1;
    }
}