Skip to content

Instantly share code, notes, and snippets.

@MikeLing
Created June 26, 2017 13:03
Show Gist options
  • Save MikeLing/384a50fa1b2267e9a14b5fcf67e59c5d to your computer and use it in GitHub Desktop.
Save MikeLing/384a50fa1b2267e9a14b5fcf67e59c5d to your computer and use it in GitHub Desktop.
TEST(BinaryLabels, serialization)
{
CBinaryLabels* labels=new CBinaryLabels(10);
labels->set_values(SGVector<float64_t>(labels->get_num_labels()));
for (index_t i=0; i<labels->get_num_labels(); ++i)
labels->set_value(i%2==0 ? 1 : -1, i);
/* generate file name */
char filename[] = "serialization-asciiCBinaryLabels.XXXXXX";
generate_temp_filename(filename);
CSerializableAsciiFile* file = new CSerializableAsciiFile(filename, 'w');
labels->save_serializable(file);
file->close();
SG_UNREF(file);
file = new CSerializableAsciiFile(filename, 'r');
CBinaryLabels* new_labels = new CBinaryLabels;
new_labels->load_serializable(file);
file->close();
SG_UNREF(file);
ASSERT(new_labels->get_num_labels () == 10)
for (int32_t i = 0; i < new_labels->get_num_labels(); i++)
{
EXPECT_EQ(
labels->get_label(i), new_labels->get_label(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment