Fixed MonteCarlo EOF problem. #459 (#531)

* Added tests for MonteCarlo varfile eof line problem

* Remove redundant variables in MonteCarlo varfile test

* Fixed MonteCarlo varfile eof line problem. #459
This commit is contained in:
Nick Kapliev 2017-12-13 18:01:31 +00:00 committed by Christopher LaChance
parent da7a79e897
commit c8619dbea7
4 changed files with 26 additions and 4 deletions

View File

@ -45,8 +45,12 @@ std::string Trick::MonteVarFile::get_next_value() {
std::getline(*input_file_stream, line);
if(input_file_stream->eof()) {
input_file_stream->close();
return "EOF";
if (line.empty()) {
input_file_stream->close();
return "EOF";
} else {
input_file_stream->seekg(0, input_file_stream->end);
}
}
}
while(line[0] == '#' || line[0] == '\0');

View File

@ -0,0 +1 @@
0 1.0000 1.5000

View File

@ -0,0 +1 @@
0 1.0000 1.5000

View File

@ -319,8 +319,6 @@ TEST_F(MonteCarloTest, TestSlaves) {
}
TEST_F(MonteCarloTest, MonteVarFile) {
std::string buffer;
std::string buffer2;
//req.add_requirement("3932595803");
// Test MonteVarFile
@ -331,6 +329,24 @@ TEST_F(MonteCarloTest, MonteVarFile) {
EXPECT_EQ(exec.variables.size(), 1) ;
}
TEST_F(MonteCarloTest, MonteVarFileWithEOFLine) {
Trick::MonteVarFile var0("time_to_fire_1", "MonteCarlo_eof_line", 2) ;
EXPECT_EQ(exec.variables.size(), 0) ;
exec.add_variable(&var0) ;
EXPECT_EQ(var0.get_next_value(), "time_to_fire_1 = 1.0000") ;
EXPECT_EQ(exec.variables.size(), 1) ;
EXPECT_EQ(var0.get_next_value(), "EOF") ;
}
TEST_F(MonteCarloTest, MonteVarFileWithLineEndedEOF) {
Trick::MonteVarFile var0("time_to_fire_1", "MonteCarlo_line_ended_eof", 2) ;
EXPECT_EQ(exec.variables.size(), 0) ;
exec.add_variable(&var0) ;
EXPECT_EQ(var0.get_next_value(), "time_to_fire_1 = 1.0000") ;
EXPECT_EQ(exec.variables.size(), 1) ;
EXPECT_EQ(var0.get_next_value(), "EOF") ;
}
TEST_F(MonteCarloTest, MonteVarRandom_Gaussian) {
std::string str;
double value;