Skip to content

Commit

Permalink
test sparse vector serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dyer committed Oct 19, 2014
1 parent 43e3a74 commit 2e485c5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions utils/sv_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#define BOOST_TEST_MODULE WeightsTest
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <sstream>
#include <string>
#include "sparse_vector.h"
#include "fdict.h"

using namespace std;

Expand Down Expand Up @@ -33,3 +38,29 @@ BOOST_AUTO_TEST_CASE(Division) {
x /= -1;
BOOST_CHECK(x == y);
}

BOOST_AUTO_TEST_CASE(Serialization) {
string arc;
FD::dict_.clear();
{
SparseVector<double> x;
x.set_value(FD::Convert("Feature1"), 1.0);
x.set_value(FD::Convert("Pi"), 3.14);
ostringstream os;
boost::archive::text_oarchive oa(os);
oa << x;
arc = os.str();
}
FD::dict_.clear();
FD::Convert("SomeNewString");
{
SparseVector<double> x;
istringstream is(arc);
boost::archive::text_iarchive ia(is);
ia >> x;
cerr << x << endl;
BOOST_CHECK_CLOSE(x.get(FD::Convert("Pi")), 3.14, 1e-9);
BOOST_CHECK_CLOSE(x.get(FD::Convert("Feature1")), 1.0, 1e-9);
}
}

0 comments on commit 2e485c5

Please sign in to comment.