@@ -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,51 @@ 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), static_cast <int >(vertexType::INH),
209+ static_cast <int >(vertexType::EXC)};
210+
211+ ASSERT_EQ (expectedData.size (), dataBuffer.size ());
212+ for (size_t i = 0 ; i < expectedData.size (); ++i) {
213+ EXPECT_EQ (expectedData[i], dataBuffer[i]);
214+ }
215+ }
216+
142217// Define the test case for compiling histories
143218TEST (Hdf5RecorderTest, CompileHistoriesTest)
144219{
@@ -190,4 +265,64 @@ TEST(Hdf5RecorderTest, CompileHistoriesTest)
190265 }
191266}
192267
268+ // Define the test case for compiling histories with vertexType enum
269+ TEST (Hdf5RecorderTest, CompileHistoriesVertexTypeTest)
270+ {
271+ // Define temporary file path for testing
272+ std::string outputFile
273+ = " ../Testing/UnitTesting/TestOutput/Hdf5test_output_compile_histories_neuron_type.h5" ;
274+
275+ // Create an instance of Hdf5Recorder
276+ Hdf5Recorder recorder (outputFile);
277+ recorder.init ();
278+
279+ // Create and configure EventBuffer for testing (stored as int)
280+ EventBuffer eventBufferNeuron (5 );
281+
282+ // Register the variable with Hdf5Recorder as DYNAMIC
283+ recorder.registerVariable (" neuron_types" , eventBufferNeuron, Recorder::UpdatedType::DYNAMIC);
284+
285+ // Expected values for checking correctness
286+ std::vector<int > expectedData;
287+
288+ // Call compileHistories() multiple times to simulate multiple epochs
289+ for (int epoch = 0 ; epoch < 3 ; ++epoch) {
290+ // Clear and insert new NeuronType values
291+ eventBufferNeuron.clear ();
292+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::EXC));
293+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::INH));
294+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::EXC));
295+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::EXC));
296+ eventBufferNeuron.insertEvent (static_cast <int >(vertexType::INH));
297+
298+ // Append expected values for this epoch
299+ expectedData.push_back (static_cast <int >(vertexType::EXC));
300+ expectedData.push_back (static_cast <int >(vertexType::INH));
301+ expectedData.push_back (static_cast <int >(vertexType::EXC));
302+ expectedData.push_back (static_cast <int >(vertexType::EXC));
303+ expectedData.push_back (static_cast <int >(vertexType::INH));
304+
305+ // Call compile history
306+ recorder.compileHistories ();
307+ }
308+
309+ // Open the HDF5 file and read back the data
310+ H5File file (outputFile, H5F_ACC_RDONLY);
311+ DataSet dataset = file.openDataSet (" neuron_types" );
312+ DataSpace dataspace = dataset.getSpace ();
313+
314+ hsize_t num_elements;
315+ dataspace.getSimpleExtentDims (&num_elements, nullptr );
316+
317+ std::vector<int > dataBuffer (num_elements);
318+ dataset.read (dataBuffer.data (), PredType::NATIVE_INT);
319+
320+ // Ensure data size matches expectation
321+ ASSERT_EQ (expectedData.size (), dataBuffer.size ());
322+
323+ // Verify that stored values match expected values
324+ for (size_t i = 0 ; i < expectedData.size (); ++i) {
325+ EXPECT_EQ (expectedData[i], dataBuffer[i]);
326+ }
327+ }
193328#endif // HDF5
0 commit comments