File: TestGraph2.cxx

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 205,984 kB
  • sloc: cpp: 2,336,570; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 181; javascript: 165; objc: 153; tcl: 59
file content (118 lines) | stat: -rw-r--r-- 2,974 bytes parent folder | download | duplicates (3)
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
118
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause

// .NAME
// .SECTION Description
// This program tests functions in vtkGraph

#include "vtkMutableDirectedGraph.h"
#include "vtkMutableUndirectedGraph.h"
#include "vtkSmartPointer.h"
#include <limits>

#include <cmath>
#include <vector>

int TestGetEdgeId();
int TestToDirectedGraph();
int TestToUndirectedGraph();

int TestGraph2(int, char*[])
{
  std::vector<int> results;

  results.push_back(TestGetEdgeId());
  results.push_back(TestToDirectedGraph());
  results.push_back(TestToUndirectedGraph());

  for (unsigned int i = 0; i < results.size(); i++)
  {
    if (results[i] == EXIT_FAILURE)
    {
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}

int TestGetEdgeId()
{
  // Create a graph
  vtkSmartPointer<vtkMutableUndirectedGraph> g = vtkSmartPointer<vtkMutableUndirectedGraph>::New();
  vtkIdType v0 = g->AddVertex();
  vtkIdType v1 = g->AddVertex();
  vtkIdType v2 = g->AddVertex();

  vtkEdgeType e0 = g->AddEdge(v0, v1);
  vtkEdgeType e1 = g->AddEdge(v1, v2);

  // Test to make sure both edges (in either orientation) are found
  if (g->GetEdgeId(v0, v1) != e0.Id || g->GetEdgeId(v1, v0) != e0.Id)
  {
    return EXIT_FAILURE;
  }

  if (g->GetEdgeId(v1, v2) != e1.Id || g->GetEdgeId(v2, v1) != e1.Id)
  {
    return EXIT_FAILURE;
  }

  // Test to make sure -1 is returned if the edge does not exist
  if (g->GetEdgeId(v1, 3) != -1)
  {
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int TestToDirectedGraph()
{
  // Create an undirected graph
  vtkSmartPointer<vtkMutableUndirectedGraph> ug = vtkSmartPointer<vtkMutableUndirectedGraph>::New();
  vtkIdType v0 = ug->AddVertex();
  vtkIdType v1 = ug->AddVertex();
  vtkIdType v2 = ug->AddVertex();

  ug->AddEdge(v0, v1);
  ug->AddEdge(v1, v2);

  // Convert it to a directed graph
  vtkSmartPointer<vtkMutableDirectedGraph> dg = vtkSmartPointer<vtkMutableDirectedGraph>::New();
  ug->ToDirectedGraph(dg);

  // Check that the number of vertices and edges is unchanged
  if (ug->GetNumberOfVertices() != dg->GetNumberOfVertices() ||
    ug->GetNumberOfEdges() != dg->GetNumberOfEdges())
  {
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

int TestToUndirectedGraph()
{
  // Create a directed graph
  vtkSmartPointer<vtkMutableDirectedGraph> dg = vtkSmartPointer<vtkMutableDirectedGraph>::New();
  vtkIdType v0 = dg->AddVertex();
  vtkIdType v1 = dg->AddVertex();
  vtkIdType v2 = dg->AddVertex();

  dg->AddEdge(v0, v1);
  dg->AddEdge(v1, v2);

  // Convert it to an undirected graph
  vtkSmartPointer<vtkMutableUndirectedGraph> ug = vtkSmartPointer<vtkMutableUndirectedGraph>::New();
  dg->ToUndirectedGraph(ug);

  // Check that the number of vertices and edges is unchanged
  if (ug->GetNumberOfVertices() != dg->GetNumberOfVertices() ||
    ug->GetNumberOfEdges() != dg->GetNumberOfEdges())
  {
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}