Skip to content

Commit

Permalink
Explicitly gave _mode to fstream in order to work
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByDrescher committed Jan 26, 2024
1 parent 98f8008 commit f243f86
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Stochastic/Tests/statstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,21 @@ const std::map<int, double> expected_S0 = {

TEST(statstest,test1) {
std::cout << "Checkpoint 0" << std::endl;
//std::string inputFileName = std::tmpnam(nullptr);
std::string inputFileName {R"(C:\CustomTemp\testme_vcell.txt)"};
std::string inputFileName = std::tmpnam(nullptr);
std::string outputFileName = std::tmpnam(nullptr);
std::map<int,double> results;
std::fstream inputFileStream{inputFileName};
ASSERT_TRUE(inputFileStream.fail());
std::cout << std::system_category().message(::GetLastError()) << std::endl;
std::cout << "Supposed file: " << inputFileName << std::endl;
return;
std::fstream outputFileStream{outputFileName};
ASSERT_FALSE(outputFileStream.fail());
std::fstream inputFileStream;
inputFileStream.open(inputFileName, fstream::out);
if (inputFileStream.fail()) {
std::perror(("File <" + inputFileName + "> could not be created.").c_str());
ASSERT_FALSE(inputFileStream.fail());
}
std::fstream outputFileStream;
outputFileStream.open(outputFileName, fstream::out);
if (outputFileStream.fail()) {
std::perror(("File <" + inputFileName + "> could not be created.").c_str());
ASSERT_FALSE(outputFileStream.fail());
}

// Setup the Gibson Solver input file
std::cout << "Checkpoint 1" << std::endl;
Expand All @@ -119,7 +123,6 @@ TEST(statstest,test1) {
if (outputFileStream.is_open()) outputFileStream.close();
inputFileStream << input_file_contents;
inputFileStream.close();
return;

// Create the Gibson Solver
std::cout << "Checkpoint 2" << std::endl;
Expand All @@ -131,7 +134,7 @@ TEST(statstest,test1) {

// Verify file contents
std::cout << "Checkpoint 4" << std::endl;
outputFileStream.open(outputFileName);
outputFileStream.open(outputFileName, fstream::in);
std::string line;
std::getline(outputFileStream, line); // remove header line
for (int i = 0; !outputFileStream.eof(); i++) {
Expand All @@ -158,10 +161,8 @@ TEST(statstest,test1) {
}
assert(accumulatedError < 0.015);
assert(maxIndividualError < 0.005);
std::cout << "Checkpoint 7" << std::endl;

delete gb;
if (inputFileStream.is_open()) inputFileStream.close();
if (outputFileStream.is_open()) outputFileStream.close();
std::cout << "Checkpoint 8" << std::endl;
}

0 comments on commit f243f86

Please sign in to comment.