Skip to content
Snippets Groups Projects
Commit e272bd0c authored by peters's avatar peters
Browse files

Add ParameterTest to test the input file.

parent 54b86584
No related branches found
No related tags found
1 merge request!56Clean up Configuration File mess. Closes #18
......@@ -112,7 +112,8 @@ struct InitCondition
bool printFiles {false};
bool doRestart {false};
bool doCheckPoint {false};
bool readGeo, isGeo, isProp, isCp;
bool readGeo {false};
bool isGeo, isProp, isCp;
bool GeometryValues {false};
bool is2ndOrderMoments {false};
bool is3rdOrderMoments {false};
......
......@@ -65,6 +65,7 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData)
this->setOutputPath(configData.getValue<std::string>("Path"));
else
throw std::runtime_error("<Path> need to be defined in config file!");
//////////////////////////////////////////////////////////////////////////
if (configData.contains("Prefix"))
this->setOutputPrefix(configData.getValue<std::string>("Prefix"));
......@@ -136,16 +137,16 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData)
this->setTimeCalcMedEnd(configData.getValue<int>("TimeEndCalcMedian"));
//////////////////////////////////////////////////////////////////////////
if (configData.contains("PressInID"))
this->setTOut(configData.getValue<int>("PressInID"));
this->setPressInID(configData.getValue<int>("PressInID"));
//////////////////////////////////////////////////////////////////////////
if (configData.contains("PressOutID"))
this->setTStartOut(configData.getValue<int>("PressOutID"));
this->setPressOutID(configData.getValue<int>("PressOutID"));
//////////////////////////////////////////////////////////////////////////
if (configData.contains("PressInZ"))
this->setTimeCalcMedStart(configData.getValue<int>("PressInZ"));
this->setPressInZ(configData.getValue<int>("PressInZ"));
//////////////////////////////////////////////////////////////////////////
if (configData.contains("PressOutZ"))
this->setTimeCalcMedEnd(configData.getValue<int>("PressOutZ"));
this->setPressOutZ(configData.getValue<int>("PressOutZ"));
//////////////////////////////////////////////////////////////////////////
//second component
......
#include <gmock/gmock.h>
#include <string>
#include "Parameter.h"
#include <basics/config/ConfigurationFile.h>
auto RealEq = [](auto value) {
#ifdef VF_DOUBLE_ACCURACY
return testing::DoubleEq(value);
#else
return testing::FloatEq(value);
#endif
};
TEST(ParameterTest, passingEmptyFileWithoutPath_ShouldThrow)
{
vf::basics::ConfigurationFile config;
std::string targetPath = __FILE__;
targetPath = targetPath.substr(0, targetPath.find_last_of('/') + 1);
targetPath += "parameterTest_emptyfile.cfg";
config.load(targetPath);
EXPECT_THROW(Parameter para(config, 1, 0), std::runtime_error);
}
TEST(ParameterTest, check_outputPath)
{
vf::basics::ConfigurationFile config;
std::string targetPath = __FILE__;
targetPath = targetPath.substr(0, targetPath.find_last_of('/') + 1);
targetPath += "parameterTest.cfg";
config.load(targetPath);
Parameter para(config, 1, 0);
// this two parameters need to be defined in each config file
EXPECT_THAT(para.getOutputPath(), testing::Eq("/output/path"));
EXPECT_THAT(para.getgeoVec(), testing::Eq("/path/to/grid/geoVec.dat"));
// ... all grid files could be tested as well
// test optional parameter
EXPECT_THAT(para.getMaxDev(), testing::Eq(2));
EXPECT_THAT(para.getDevices(), testing::ElementsAreArray({2,3}));
EXPECT_THAT(para.getOutputPrefix(), testing::Eq("MyPrefix"));
EXPECT_THAT(para.getPrintFiles(), testing::Eq(true));
EXPECT_THAT(para.getIsGeometryValues(), testing::Eq(true));
EXPECT_THAT(para.getCalc2ndOrderMoments(), testing::Eq(true));
EXPECT_THAT(para.getCalc3rdOrderMoments(), testing::Eq(true));
EXPECT_THAT(para.getCalcHighOrderMoments(), testing::Eq(true));
EXPECT_THAT(para.getCalcMedian(), testing::Eq(true));
EXPECT_THAT(para.getCalcCp(), testing::Eq(true));
EXPECT_THAT(para.getCalcDragLift(), testing::Eq(true));
}
# this two parameters need to be defined in each config file
Path = /output/path
GridPath = /path/to/grid
# optional parameter
NumberOfDevices = 2
Devices = 2 3
Prefix = MyPrefix
WriteGrid = true
GeometryValues = true
calc2ndOrderMoments = true
calc3rdOrderMoments = true
calcHigherOrderMoments = true
calcMedian = true
calcCp = true
calcDrafLift = true
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment