Commit ec4f55f9 authored by Pierre Fernbach's avatar Pierre Fernbach
Browse files

[Tests] add test case for serialization of contactModel

parent 73409534
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_scenario_contact_model_planar_hpp__
#define __multicontact_api_scenario_contact_model_planar_hpp__
#include "multicontact-api/scenario/fwd.hpp"
#include "multicontact-api/serialization/archive.hpp"
#include <iostream>
#include <Eigen/Dense>
namespace multicontact_api {
namespace scenario {
template <typename _Scalar>
struct ContactModelPlanarTpl : public serialization::Serializable<ContactModelPlanarTpl<_Scalar> > {
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef _Scalar Scalar;
/// \brief Default constructor.
ContactModelPlanarTpl() : m_mu(-1.), m_ZMP_radius(-1.) {}
/// \brief Default constructor.
ContactModelPlanarTpl(const Scalar mu, const Scalar ZMP_radius) : m_mu(mu), m_ZMP_radius(ZMP_radius) {}
/// \brief Copy constructor
template <typename S2>
explicit ContactModelPlanarTpl(const ContactModelPlanarTpl<S2>& other)
: m_mu(other.mu), m_ZMP_radius(other.ZMP_radius) {}
template <typename S2>
bool operator==(const ContactModelPlanarTpl<S2>& other) const {
return m_mu == other.m_mu && m_ZMP_radius == other.m_ZMP_radius;
}
template <typename S2>
bool operator!=(const ContactModelPlanarTpl<S2>& other) const {
return !(*this == other);
}
void disp(std::ostream& os) const {
os << "mu: " << m_mu << std::endl << "ZMP radius: " << m_ZMP_radius << std::endl;
}
template <typename S2>
friend std::ostream& operator<<(std::ostream& os, const ContactModelPlanarTpl<S2>& cp) {
cp.disp(os);
return os;
}
/// \brief Friction coefficient.
Scalar m_mu;
/// \brief ZMP radius.
Scalar m_ZMP_radius;
private:
// Serialization of the class
friend class boost::serialization::access;
template <class Archive>
void save(Archive& ar, const unsigned int /*version*/) const {
ar& boost::serialization::make_nvp("mu", m_mu);
ar& boost::serialization::make_nvp("ZMP_radius", m_ZMP_radius);
}
template <class Archive>
void load(Archive& ar, const unsigned int /*version*/) {
ar >> boost::serialization::make_nvp("mu", m_mu);
ar >> boost::serialization::make_nvp("ZMP_radius", m_ZMP_radius);
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
} // namespace scenario
} // namespace multicontact_api
#endif // ifndef __multicontact_api_scenario_contact_model_planar_hpp__
......@@ -351,8 +351,29 @@ BOOST_AUTO_TEST_CASE(contact_model) {
BOOST_CHECK(mp1 == mp2);
mp1.m_mu = 0.5;
BOOST_CHECK(mp1 != mp2);
// TODO : check serialization
ContactModelPlanar mp3(mp1);
BOOST_CHECK(mp1 == mp3);
mp3.m_ZMP_radius = 0.5;
BOOST_CHECK(mp1 != mp3);
std::cout<<"ContactModel Planar before serialization : \n "<<mp1<<std::endl;
std::string fileName("fileTest_contactModel");
mp1.saveAsText(fileName + ".txt");
ContactModelPlanar mp_from_text;
mp_from_text.loadFromText(fileName + ".txt");
std::cout<<"ContactModel Planar after serialization : \n "<<mp_from_text<<std::endl;
BOOST_CHECK(mp1 == mp_from_text);
mp1.saveAsXML(fileName + ".xml", "ContactModel");
ContactModelPlanar mp_from_xml;
mp_from_xml.loadFromXML(fileName + ".xml", "ContactModel");
BOOST_CHECK(mp1 == mp_from_xml);
mp1.saveAsBinary(fileName);
ContactModelPlanar mp_from_bin;
mp_from_bin.loadFromBinary(fileName);
BOOST_CHECK(mp1 == mp_from_bin);
}
BOOST_AUTO_TEST_CASE(contact_patch) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment