MCPcopy Create free account
hub / github.com/Kitware/VTK / TestGraphAttributes

Function TestGraphAttributes

Common/DataModel/Testing/Cxx/TestGraphAttributes.cxx:148–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148int TestGraphAttributes(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
149{
150 int errors = 0;
151
152 VTK_CREATE(vtkMutableDirectedGraph, mdgTree);
153
154 VTK_CREATE(vtkDirectedGraph, dg);
155 VTK_CREATE(vtkTree, t);
156
157 // Create some vertex property arrays
158 VTK_CREATE(vtkVariantArray, vertexPropertyArr);
159 int numVertexProperties = 2;
160 vertexPropertyArr->SetNumberOfValues(numVertexProperties);
161
162 VTK_CREATE(vtkStringArray, vertexProp0Array);
163 vertexProp0Array->SetName("labels");
164 mdgTree->GetVertexData()->AddArray(vertexProp0Array);
165
166 VTK_CREATE(vtkIntArray, vertexProp1Array);
167 vertexProp1Array->SetName("weight");
168 mdgTree->GetVertexData()->AddArray(vertexProp1Array);
169
170 const char* vertexLabel[] = { "Dick", "Jane", "Sally", "Spot", "Puff" };
171
172 const char* stringProp;
173 int weight;
174
175 for (vtkIdType i = 0; i < 10; ++i)
176 {
177 stringProp = vertexLabel[rand() % 5];
178 weight = rand() % 10;
179 // std::cout << myRank <<" vertex "<< v <<","<< stringProp <<","<<weight<< std::endl;
180 vertexPropertyArr->SetValue(0, stringProp);
181 vertexPropertyArr->SetValue(1, weight);
182 mdgTree->AddVertex(vertexPropertyArr);
183 }
184
185 // Create a valid tree.
186 mdgTree->AddEdge(0, 1);
187 mdgTree->AddEdge(0, 2);
188 mdgTree->AddEdge(0, 3);
189 mdgTree->AddEdge(1, 4);
190 mdgTree->AddEdge(1, 5);
191 mdgTree->AddEdge(2, 6);
192 mdgTree->AddEdge(2, 7);
193 mdgTree->AddEdge(3, 8);
194 mdgTree->AddEdge(3, 9);
195
196 std::cerr << "Testing graph conversions ..." << std::endl;
197 if (!t->CheckedShallowCopy(mdgTree))
198 {
199 std::cerr << "ERROR: Cannot set valid tree." << std::endl;
200 ++errors;
201 }
202
203 if (!dg->CheckedShallowCopy(mdgTree))
204 {
205 std::cerr << "ERROR: Cannot set valid directed graph." << std::endl;

Callers

nothing calls this directly

Calls 11

TestGraphAttribIteratorsFunction · 0.85
GetVertexDataMethod · 0.80
IsSameStructureMethod · 0.80
GetNumberOfVerticesMethod · 0.80
SetNumberOfValuesMethod · 0.45
SetNameMethod · 0.45
AddArrayMethod · 0.45
SetValueMethod · 0.45
AddVertexMethod · 0.45
AddEdgeMethod · 0.45
CheckedShallowCopyMethod · 0.45

Tested by

no test coverage detected