7
7
#include < iostream>
8
8
#include < cstdio>
9
9
10
+ #include " VCELL/SimulationMessaging.h"
11
+
10
12
const char * input_file_contents = R"INPUT_FILE(
11
13
<control>
12
14
STARTING_TIME 0.0
@@ -98,70 +100,68 @@ const std::map<int, double> expected_S0 = {
98
100
99
101
TEST (statstest,test1) {
100
102
std::cout << " Checkpoint 0" << std::endl;
101
- char *temp_input_file_name = new char [1000 ] {0 };
102
- char *temp_output_file_name = new char [1000 ] {0 };
103
- std::string in_prefix = testing::TempDir () + " input_XXXXXX" ;
104
- std::string out_prefix = testing::TempDir () + " output_XXXXXX" ;
105
- strncpy (temp_input_file_name, in_prefix.c_str (), in_prefix.length ());
106
- strncpy (temp_output_file_name, out_prefix.c_str (), out_prefix.length ());
103
+ // std::string inputFileName = std::tmpnam(nullptr);
104
+ std::string inputFileName {R"( C:\CustomTemp\testme_vcell.txt)" };
105
+ std::string outputFileName = std::tmpnam (nullptr );
106
+ std::map<int ,double > results;
107
+ std::fstream inputFileStream{inputFileName};
108
+ ASSERT_TRUE (inputFileStream.fail ());
109
+ std::cout << std::system_category ().message (::GetLastError ()) << std::endl;
110
+ std::cout << " Supposed file: " << inputFileName << std::endl;
111
+ return ;
112
+ std::fstream outputFileStream{outputFileName};
113
+ ASSERT_FALSE (outputFileStream.fail ());
114
+
115
+ // Setup the Gibson Solver input file
107
116
std::cout << " Checkpoint 1" << std::endl;
108
- assert (mkstemp (temp_input_file_name) != -1 );
109
- assert (mkstemp (temp_output_file_name) != -1 );
110
- std::ofstream input_file (temp_input_file_name);
111
- bool bWroteFile = false ;
112
- if (input_file.is_open ()){
113
- input_file << input_file_contents;
114
- input_file.close ();
115
- bWroteFile = true ;
116
- }
117
- ASSERT_TRUE (bWroteFile);
117
+ std::cout << " >> " << " Input: <" << inputFileName << " >;" << std::endl;
118
+ std::cout << " >> " << " Output: <" << outputFileName << " >;" << std::endl;
119
+ if (outputFileStream.is_open ()) outputFileStream.close ();
120
+ inputFileStream << input_file_contents;
121
+ inputFileStream.close ();
122
+ return ;
123
+
124
+ // Create the Gibson Solver
118
125
std::cout << " Checkpoint 2" << std::endl;
119
- Gibson *gb= new Gibson (temp_input_file_name, temp_output_file_name);
126
+ auto *gb = new Gibson (inputFileName.c_str (), outputFileName.c_str ());
127
+
128
+ // Launch the test
120
129
std::cout << " Checkpoint 3" << std::endl;
121
130
gb->march ();
122
131
132
+ // Verify file contents
123
133
std::cout << " Checkpoint 4" << std::endl;
124
- // verify file contents
125
- std::ifstream outfile (temp_output_file_name);
126
- string line;
127
- getline (outfile, line); // remove header line
128
- // std::cout << line << std::endl;
129
- // std::cout.flush();
130
-
134
+ outputFileStream.open (outputFileName);
135
+ std::string line;
136
+ std::getline (outputFileStream, line); // remove header line
137
+ for (int i = 0 ; !outputFileStream.eof (); i++) {
138
+ std::getline (outputFileStream, line);
139
+ // if index found in expected_S0 map, store in results map
140
+ if (expected_S0.find (i) != expected_S0.end ()){
141
+ float t, s0, s1, s2;
142
+ // extract space separated values for t, s0, s1 and s2 from line
143
+ std::stringstream line_stream (line);
144
+ line_stream >> t >> s0 >> s1 >> s2;
145
+ results[i] = s0;
146
+ }
147
+ }
148
+ outputFileStream.close ();
149
+
150
+ // compare the expected and actual values
131
151
std::cout << " Checkpoint 5" << std::endl;
132
- std::map<int ,double > results;
133
- int i = 0 ;
134
- while (getline (outfile, line)){
135
- // if index found in expected_S0 map, store in results map
136
- if (expected_S0.find (i) != expected_S0.end ()){
137
- float t, s0, s1, s2;
138
- // extract space separated values for t, s0, s1 and s2 from line
139
- std::stringstream line_stream (line);
140
- line_stream >> t >> s0 >> s1 >> s2;
141
- results[i] = s0;
142
- // std::cout << line << std::endl;
143
- // std::cout.flush();
144
- }
145
- i++;
146
- }
147
- std::cout << " Checkpoint 6" << std::endl;
148
- // compare the expected and actual values
149
- double accum_error = 0.0 ;
150
- double max_error = 0.0 ;
152
+ double accumulatedError = 0.0 , maxIndividualError = 0.0 ;
151
153
for (auto const & expected : expected_S0){
152
- double s0_given = expected.second ;
153
- double s0_computed = results[expected.first ];
154
- double abserr = std::abs (s0_given - s0_computed);
155
- // std::cout << "t=" << expected.first << " expected=" << s0_given << " computed=" << s0_computed << " abserr=" << abserr << std::endl;
156
- accum_error += abserr;
157
- max_error = std::max (max_error, abserr);
154
+ double absoluteError = std::abs (expected.second - results[expected.first ]);
155
+ // std::cout << "t=" << expected.first << " expected=" << expected.second << " computed=" << results[expected.first] << " abserr=" << abserr << std::endl;
156
+ accumulatedError += absoluteError;
157
+ maxIndividualError = std::max (maxIndividualError, absoluteError);
158
158
}
159
- assert (accum_error < 0.015 );
160
- assert (max_error < 0.005 );
159
+ assert (accumulatedError < 0.015 );
160
+ assert (maxIndividualError < 0.005 );
161
161
std::cout << " Checkpoint 7" << std::endl;
162
162
163
163
delete gb;
164
- delete[] temp_input_file_name ;
165
- delete[] temp_output_file_name ;
164
+ if (inputFileStream. is_open ()) inputFileStream. close () ;
165
+ if (outputFileStream. is_open ()) outputFileStream. close () ;
166
166
std::cout << " Checkpoint 8" << std::endl;
167
167
}
0 commit comments