@@ -95,6 +95,36 @@ TEST(Hdf5RecorderTest, RegisterVectorVariableTest)
9595 ASSERT_EQ (Recorder::UpdatedType::DYNAMIC, variableTable[1 ].variableType_ );
9696}
9797
98+ // Unit test for registerVariable method with a vector of NeuronType enums
99+ TEST (Hdf5RecorderTest, RegisterVertexTypeTest)
100+ {
101+ // Create an instance of Hdf5Recorder
102+ std::string outputFile = " ../Testing/UnitTesting/TestOutput/Hdf5test_output_register.h5" ;
103+ Hdf5Recorder recorder (outputFile);
104+ recorder.init ();
105+
106+ // Create a vector of NeuronType enums
107+ RecordableVector<vertexType> neuronTypes;
108+ neuronTypes.resize (2 );
109+ neuronTypes[0 ] = vertexType::EXC;
110+ neuronTypes[1 ] = vertexType::INH;
111+
112+ // register the vector of NeuronTypes
113+ recorder.registerVariable (" neuron_types" , neuronTypes, Recorder::UpdatedType::DYNAMIC);
114+
115+ // Verify that the registered variables are stored correctly
116+ const auto &variableTable = recorder.getVariableTable ();
117+ ASSERT_EQ (1 , variableTable.size ()); // Only one variable, "neuron_types"
118+
119+ // Verify that the registered variable name matches
120+ ASSERT_EQ (" neuron_types" , variableTable[0 ].variableName_ );
121+ ASSERT_EQ (&neuronTypes, &variableTable[0 ].variableLocation_ );
122+
123+ // Verify the type of update for this variable
124+ ASSERT_EQ (Recorder::UpdatedType::DYNAMIC, variableTable[0 ].variableType_ );
125+ }
126+
127+
98128// Define the test case for saving simulation data
99129TEST (Hdf5RecorderTest, SaveSimDataTest)
100130{
@@ -139,6 +169,52 @@ TEST(Hdf5RecorderTest, SaveSimDataTest)
139169 }
140170}
141171
172+ // Unit test for saving simulation data with a vector of NeuronType enums
173+ TEST (Hdf5RecorderTest, SaveSimDataVertexTypeTest)
174+ {
175+ // Define a temporary file path for testing
176+ std::string outputFile = " ../Testing/UnitTesting/TestOutput/Hdf5test_output_save.h5" ;
177+
178+ // Create an instance of Hdf5Recorder
179+ Hdf5Recorder recorder (outputFile);
180+ recorder.init ();
181+
182+ // Create and configure RecordableVector<vertexType> for testing
183+ RecordableVector<vertexType> neuronTypes;
184+ neuronTypes.resize (3 );
185+ neuronTypes[0 ] = vertexType::EXC;
186+ neuronTypes[1 ] = vertexType::INH;
187+ neuronTypes[2 ] = vertexType::EXC;
188+
189+ // Register the variable with Hdf5Recorder
190+ recorder.registerVariable (" neuron_types" , neuronTypes, Recorder::UpdatedType::CONSTANT);
191+
192+ // Call saveSimData() to write the data to the file
193+ recorder.saveSimData ();
194+
195+ // Open the HDF5 file and read back the data
196+ H5File file (outputFile, H5F_ACC_RDONLY);
197+ DataSet dataset = file.openDataSet (" neuron_types" );
198+ DataSpace dataspace = dataset.getSpace ();
199+
200+ hsize_t num_elements;
201+ dataspace.getSimpleExtentDims (&num_elements, nullptr );
202+
203+ // Read the data into a buffer
204+ vector<int > dataBuffer (num_elements);
205+ dataset.read (dataBuffer.data (), PredType::NATIVE_INT);
206+
207+ // Verify the data matches the expected NeuronType values (converted to int)
208+ vector<int > expectedData = {static_cast <int >(vertexType::EXC),
209+ static_cast <int >(vertexType::INH),
210+ static_cast <int >(vertexType::EXC)};
211+
212+ ASSERT_EQ (expectedData.size (), dataBuffer.size ());
213+ for (size_t i = 0 ; i < expectedData.size (); ++i) {
214+ EXPECT_EQ (expectedData[i], dataBuffer[i]);
215+ }
216+ }
217+
142218// Define the test case for compiling histories
143219TEST (Hdf5RecorderTest, CompileHistoriesTest)
144220{
@@ -190,4 +266,64 @@ TEST(Hdf5RecorderTest, CompileHistoriesTest)
190266 }
191267}
192268
269+ // Define the test case for compiling histories with vertexType enum
270+ TEST (Hdf5RecorderTest, CompileHistoriesVertexTypeTest)
271+ {
272+ // Define temporary file path for testing
273+ std::string outputFile
274+ = " ../Testing/UnitTesting/TestOutput/Hdf5test_output_compile_histories_neuron_type.h5" ;
275+
276+ // Create an instance of Hdf5Recorder
277+ Hdf5Recorder recorder (outputFile);
278+ recorder.init ();
279+
280+ // Create and configure EventBuffer for testing (stored as int)
281+ EventBuffer eventBufferNeuron (5 );
282+
283+ // Register the variable with Hdf5Recorder as DYNAMIC
284+ recorder.registerVariable (" neuron_types" , eventBufferNeuron, Recorder::UpdatedType::DYNAMIC);
285+
286+ // Expected values for checking correctness
287+ std::vector<int > expectedData;
288+
289+ // Call compileHistories() multiple times to simulate multiple epochs
290+ for (int epoch = 0 ; epoch < 3 ; ++epoch) {
291+ // Clear and insert new NeuronType values
292+ eventBufferNeuron.clear ();
293+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::EXC));
294+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::INH));
295+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::EXC));
296+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::EXC));
297+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::INH));
298+
299+ // Append expected values for this epoch
300+ expectedData.push_back (static_cast <int >(vertexType::EXC));
301+ expectedData.push_back (static_cast <int >(vertexType::INH));
302+ expectedData.push_back (static_cast <int >(vertexType::EXC));
303+ expectedData.push_back (static_cast <int >(vertexType::EXC));
304+ expectedData.push_back (static_cast <int >(vertexType::INH));
305+
306+ // Call compile history
307+ recorder.compileHistories ();
308+ }
309+
310+ // Open the HDF5 file and read back the data
311+ H5File file (outputFile, H5F_ACC_RDONLY);
312+ DataSet dataset = file.openDataSet (" neuron_types" );
313+ DataSpace dataspace = dataset.getSpace ();
314+
315+ hsize_t num_elements;
316+ dataspace.getSimpleExtentDims (&num_elements, nullptr );
317+
318+ std::vector<int > dataBuffer (num_elements);
319+ dataset.read (dataBuffer.data (), PredType::NATIVE_INT);
320+
321+ // Ensure data size matches expectation
322+ ASSERT_EQ (expectedData.size (), dataBuffer.size ());
323+
324+ // Verify that stored values match expected values
325+ for (size_t i = 0 ; i < expectedData.size (); ++i) {
326+ EXPECT_EQ (expectedData[i], dataBuffer[i]);
327+ }
328+ }
193329#endif // HDF5
0 commit comments