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
|
#include "vtkComputeQuartiles.h"
#include "vtkDoubleArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkNew.h"
#include "vtkStatisticsAlgorithm.h"
#include "vtkTable.h"
#include "vtkTestErrorObserver.h"
#include "vtkExecutive.h"
#define CHECK_ERROR_MSG(observer, msg) \
{ \
std::string expectedMsg(msg); \
if (!observer->GetError()) \
{ \
std::cout << "ERROR: Failed to catch any error. Expected the error message to contain \"" << expectedMsg << std::endl; \
} \
else \
{ \
std::string gotMsg(observer->GetErrorMessage()); \
if (gotMsg.find(expectedMsg) == std::string::npos) \
{ \
std::cout << "ERROR: Error message does not contain \"" << expectedMsg << "\" got \n\"" << gotMsg << std::endl; \
} \
} \
} \
observer->Clear()
//----------------------------------------------------------------------------
int TestComputeQuartiles(int , char * [])
{
vtkNew<vtkDoubleArray> arrFirstVariable;
arrFirstVariable->SetName("Math");
vtkNew<vtkDoubleArray> arrSecondVariable;
arrSecondVariable->SetName("French");
// Create a two columns table
vtkNew<vtkTable> table;
table->AddColumn(arrFirstVariable.GetPointer());
table->AddColumn(arrSecondVariable.GetPointer());
const int numNotes = 20;
table->SetNumberOfRows(numNotes);
const double MathValue[] =
{
18, 20, 20, 16,
12, 14, 16, 14,
14, 13, 16, 18,
6, 10, 16, 14,
4, 16, 16, 14
};
const double FrenchValue[] =
{
14, 12, 14, 16,
12, 14, 16, 4,
4, 10, 6, 20,
14, 16, 14, 14,
12, 2, 14, 8
};
for (int i = 0; i < numNotes; ++i)
{
table->SetValue(i, 0, MathValue[i]);
table->SetValue(i, 1, FrenchValue[i]);
}
// Run Compute Quantiles
vtkNew<vtkComputeQuartiles> quartiles;
vtkNew<vtkTest::ErrorObserver> errorObserver1;
// First verify that absence of input does not cause trouble
quartiles->GetExecutive()->AddObserver(vtkCommand::ErrorEvent,errorObserver1.GetPointer());
quartiles->Update();
CHECK_ERROR_MSG(errorObserver1, "Input port 0 of algorithm vtkComputeQuartiles");
// Now set the real input table
quartiles->SetInputData(vtkStatisticsAlgorithm::INPUT_DATA, table.GetPointer());
quartiles->Update();
vtkTable *outTable = quartiles->GetOutput();
const double MathQuartiles[] =
{
4, 13.5, 15, 16, 20
};
const double FrenchQuartiles[] =
{
2, 9, 14, 14, 20
};
bool ret = EXIT_SUCCESS;
for (int i = 0; i < 5; i++)
{
if (outTable->GetValue(i, 0).ToFloat() != MathQuartiles[i] ||
outTable->GetValue(i, 1).ToFloat() != FrenchQuartiles[i])
{
ret = EXIT_FAILURE;
}
}
if (ret != EXIT_SUCCESS)
{
cout << "Failure!" << endl;
outTable->Dump();
}
return ret;
}
|