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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include "persalys/MeshDefinitionWizard.hxx"
#include "persalys/ImportedMeshModel.hxx"
#include "persalys/GridMeshModel.hxx"
#include <openturns/OTtypes.hxx>
#include <QtTest/QtTest>
#include <QAbstractButton>
namespace PERSALYS
{
class TestMeshDefinitionWizard : public QObject
{
Q_OBJECT
public:
TestMeshDefinitionWizard()
{
}
private slots:
void TestGridMeshModel()
{
// create the mesh
GridMeshModel meshModel(OT::Interval(0., 12.), OT::Indices(1, 5));
// create the wizard
MeshDefinitionWizard wizard(meshModel);
wizard.show();
// checks
QVERIFY2(wizard.nextId() == -1, "Next page ID must be -1");
QVERIFY2(wizard.methodGroup_->checkedId() == MeshDefinitionWizard::Grid, "Checked button must be Grid");
QVERIFY2(!wizard.sampleWidget_->dataPreviewTableView_->isEnabled(), "Table view must be not enabled");
QVERIFY2(static_cast<QWidget*>(wizard.tableModel_->parent())->isEnabled(), "Table view must be enabled");
QVERIFY2(wizard.validateCurrentPage(), "Page must be valid");
QVERIFY2(wizard.errorMessageLabel_->text().isEmpty(), "Label must be empty");
bool analysisEquality = wizard.getMesh().getPythonScript() == meshModel.getPythonScript();
QVERIFY2(analysisEquality, "The two GridMeshModel must be equal");
wizard.tableModel_->setData(wizard.tableModel_->index(0, 2), 14., Qt::EditRole);
QVERIFY2(!wizard.validateCurrentPage(), "Page must be not valid");
QVERIFY2(!wizard.errorMessageLabel_->text().isEmpty(), "Label must be not empty");
wizard.tableModel_->setData(wizard.tableModel_->index(0, 2), 0., Qt::EditRole);
QVERIFY2(wizard.validateCurrentPage(), "Page must be valid");
QVERIFY2(wizard.errorMessageLabel_->text().isEmpty(), "Label must be empty");
wizard.tableModel_->setData(wizard.tableModel_->index(0, 4), 1, Qt::EditRole);
QVERIFY2(!wizard.validateCurrentPage(), "Page must be not valid");
QVERIFY2(!wizard.errorMessageLabel_->text().isEmpty(), "Label must be not empty");
wizard.tableModel_->setData(wizard.tableModel_->index(0, 4), 5, Qt::EditRole);
QVERIFY2(wizard.validateCurrentPage(), "Page must be valid");
QVERIFY2(wizard.errorMessageLabel_->text().isEmpty(), "Label must be empty");
analysisEquality = wizard.getMesh().getPythonScript() == meshModel.getPythonScript();
QVERIFY2(analysisEquality, "The two GridMeshModel must be equal");
}
void TestImportedMeshModel()
{
QTemporaryFile file;
QVERIFY2(file.open(), "Can not open the file");
OT::Sample(2, OT::Point(1, 2.5)).exportToCSVFile(file.fileName().toStdString());
// create the mesh
ImportedMeshModel meshModel(file.fileName().toStdString());
// create the wizard
MeshDefinitionWizard wizard(meshModel);
wizard.show();
// checks
ImportSampleWidget * sampleWidget = wizard.sampleWidget_;
QVERIFY2(wizard.nextId() == -1, "Next page ID must be -1");
QVERIFY2(!static_cast<QWidget*>(wizard.tableModel_->parent())->isEnabled(), "Table view must be not enabled");
QVERIFY2(sampleWidget->dataPreviewTableView_->isEnabled(), "Table view must be enabled");
QVERIFY2(wizard.validateCurrentPage(), "Page must be valid");
QVERIFY2(sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be empty");
OT::Sample(1, OT::Point(1, 2.5)).exportToCSVFile(file.fileName().toStdString());
sampleWidget->setData(file.fileName());
QVERIFY2(!wizard.validateCurrentPage(), "Page must be not valid");
QVERIFY2(!sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be not empty");
OT::Sample(2, OT::Point(2, 2.5)).exportToCSVFile(file.fileName().toStdString());
sampleWidget->setData(file.fileName());
sampleWidget->dataPreviewTableView_->model()->setHeaderData(0, Qt::Horizontal, "", Qt::DisplayRole);
QVERIFY2(!wizard.validateCurrentPage(), "Page must be not valid");
QVERIFY2(!sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be not empty");
sampleWidget->dataPreviewTableView_->model()->setHeaderData(1, Qt::Horizontal, "t", Qt::DisplayRole);
QVERIFY2(wizard.validateCurrentPage(), "Page must be valid");
QVERIFY2(sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be empty");
sampleWidget->dataPreviewTableView_->model()->setHeaderData(0, Qt::Horizontal, "t", Qt::DisplayRole);
QVERIFY2(!wizard.validateCurrentPage(), "Page must be not valid");
QVERIFY2(!sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be not empty");
sampleWidget->dataPreviewTableView_->model()->setHeaderData(1, Qt::Horizontal, "", Qt::DisplayRole);
QVERIFY2(wizard.validateCurrentPage(), "Page must be valid");
QVERIFY2(sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be empty");
bool analysisEquality = wizard.getMesh().getPythonScript() == meshModel.getPythonScript();
QVERIFY2(analysisEquality, "The two ImportedMeshModel must be equal");
}
void TestMeshModification()
{
// create the mesh
GridMeshModel meshModel(OT::Interval(0., 12.), OT::Indices(1, 5));
// create the wizard
MeshDefinitionWizard wizard(meshModel);
wizard.show();
// checks
ImportSampleWidget * sampleWidget = wizard.sampleWidget_;
wizard.methodGroup_->button(MeshDefinitionWizard::Import)->click();
QVERIFY2(sampleWidget->dataPreviewTableView_->isEnabled(), "Table view must be enabled");
QTemporaryFile file;
QVERIFY2(file.open(), "Can not open the file");
sampleWidget->setData(file.fileName());
QVERIFY2(!wizard.validateCurrentPage(), "Page must be not valid");
QVERIFY2(!sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be not empty");
OT::Sample(2, OT::Point(1, 2.5)).exportToCSVFile(file.fileName().toStdString());
sampleWidget->setData(file.fileName());
QVERIFY2(wizard.validateCurrentPage(), "Page must be valid");
QVERIFY2(sampleWidget->errorMessageLabel_->text().isEmpty(), "Label must be empty");
bool analysisEquality = wizard.getMesh().getPythonScript() == ImportedMeshModel(file.fileName().toStdString()).getPythonScript();
QVERIFY2(analysisEquality, "The two ImportedMeshModel must be equal");
}
};
}
QTEST_MAIN(PERSALYS::TestMeshDefinitionWizard)
#include "t_MeshDefinitionWizard_std.moc"
|