| 19 | #define ARRAY_SIZE 2048 |
| 20 | |
| 21 | int TestSortDataArray(int, char*[]) |
| 22 | { |
| 23 | vtkIdType i; |
| 24 | vtkTimerLog* timer = vtkTimerLog::New(); |
| 25 | int retVal = 0; |
| 26 | |
| 27 | //--------------------------------------------------------------------------- |
| 28 | // Sort data array |
| 29 | std::cout << "Building array----------" << std::endl; |
| 30 | vtkIntArray* keys = vtkIntArray::New(); |
| 31 | keys->SetNumberOfComponents(1); |
| 32 | keys->SetNumberOfTuples(ARRAY_SIZE); |
| 33 | for (i = 0; i < ARRAY_SIZE; i++) |
| 34 | { |
| 35 | keys->SetComponent(i, 0, static_cast<int>(vtkMath::Random(0, ARRAY_SIZE * 4))); |
| 36 | } |
| 37 | |
| 38 | std::cout << "Sorting array" << std::endl; |
| 39 | timer->StartTimer(); |
| 40 | vtkSortDataArray::Sort(keys); |
| 41 | timer->StopTimer(); |
| 42 | |
| 43 | std::cout << "Time to sort array: " << timer->GetElapsedTime() << " sec" << std::endl; |
| 44 | |
| 45 | for (i = 0; i < ARRAY_SIZE - 1; i++) |
| 46 | { |
| 47 | if (keys->GetComponent(i, 0) > keys->GetComponent(i + 1, 0)) |
| 48 | { |
| 49 | std::cout << "Array not properly sorted!" << std::endl; |
| 50 | retVal = 1; |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | std::cout << "Array consistency check finished\n" << std::endl; |
| 55 | |
| 56 | std::cout << "Sorting sorted array" << std::endl; |
| 57 | timer->StartTimer(); |
| 58 | vtkSortDataArray::Sort(keys); |
| 59 | timer->StopTimer(); |
| 60 | |
| 61 | std::cout << "Time to sort array: " << timer->GetElapsedTime() << " sec" << std::endl; |
| 62 | |
| 63 | for (i = 0; i < ARRAY_SIZE - 1; i++) |
| 64 | { |
| 65 | if (keys->GetComponent(i, 0) > keys->GetComponent(i + 1, 0)) |
| 66 | { |
| 67 | std::cout << "Array not properly sorted!" << std::endl; |
| 68 | retVal = 1; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | std::cout << "Array consistency check finished\n" << std::endl; |
| 73 | |
| 74 | //--------------------------------------------------------------------------- |
| 75 | // Sort id list (ascending) |
| 76 | std::cout << "Building id list (ascending order)----------" << std::endl; |
| 77 | vtkIdList* ids = vtkIdList::New(); |
| 78 | ids->SetNumberOfIds(ARRAY_SIZE); |
nothing calls this directly
no test coverage detected