diff --git a/unittest/python/test_variant.py.in b/unittest/python/test_variant.py.in index b019514cd..a7590a3fa 100644 --- a/unittest/python/test_variant.py.in +++ b/unittest/python/test_variant.py.in @@ -6,7 +6,12 @@ V2 = variant_module.V2 VariantHolder = variant_module.VariantHolder VariantFullHolder = variant_module.VariantFullHolder make_variant = variant_module.make_variant -make_variant_full = variant_module.make_variant_full +make_variant_full_none = variant_module.make_variant_full_none +make_variant_full_float = variant_module.make_variant_full_float +make_variant_full_int = variant_module.make_variant_full_int +make_variant_full_bool = variant_module.make_variant_full_bool +make_variant_full_str = variant_module.make_variant_full_str +make_variant_full_complex = variant_module.make_variant_full_complex variant = make_variant() assert isinstance(variant, V1) @@ -44,9 +49,34 @@ assert isinstance(variant_holder.variant, V2) assert variant_holder.variant.v == v2.v # Test variant that hold a None value -v_full = make_variant_full() +v_full = make_variant_full_none() assert v_full is None +# Test variant that hold a float value +v_full = make_variant_full_float() +assert v_full == 3.14 +assert isinstance(v_full, float) + +# Test variant that hold a int value +v_full = make_variant_full_int() +assert v_full == 3 +assert isinstance(v_full, int) + +# Test variant that hold a bool value +v_full = make_variant_full_bool() +assert not v_full +assert isinstance(v_full, bool) + +# Test variant that hold a str value +v_full = make_variant_full_str() +assert v_full == "str" +assert isinstance(v_full, str) + +# Test variant that hold a complex value +v_full = make_variant_full_complex() +assert v_full == 1 + 0j +assert isinstance(v_full, complex) + variant_full_holder = VariantFullHolder() # Test None @@ -81,3 +111,13 @@ assert isinstance(variant_full_holder.variant, int) variant_full_holder.variant = 3.14 assert variant_full_holder.variant == 3.14 assert isinstance(variant_full_holder.variant, float) + +# Test str +variant_full_holder.variant = "str" +assert variant_full_holder.variant == "str" +assert isinstance(variant_full_holder.variant, str) + +# Test complex +variant_full_holder.variant = 1 + 0j +assert variant_full_holder.variant == 1 + 0j +assert isinstance(variant_full_holder.variant, complex) diff --git a/unittest/variant.cpp.in b/unittest/variant.cpp.in index 12f669937..5d8f75ebd 100644 --- a/unittest/variant.cpp.in +++ b/unittest/variant.cpp.in @@ -4,6 +4,9 @@ #include #include +#include +#include + #cmakedefine TEST_TYPE @TEST_TYPE@ #define VARIANT TEST_TYPE @@ -32,12 +35,18 @@ struct MyVariantNoneHelper > { }; #endif -typedef typename MyVariantNoneHelper >::type +typedef typename MyVariantNoneHelper< + VARIANT > >::type MyVariantFull; MyVariant make_variant() { return V1(); } -MyVariantFull make_variant_full() { return MyVariantFull(); } +MyVariantFull make_variant_full_none() { return MyVariantFull(); } +MyVariantFull make_variant_full_float() { return 3.14; } +MyVariantFull make_variant_full_int() { return 3; } +MyVariantFull make_variant_full_bool() { return false; } +MyVariantFull make_variant_full_str() { return std::string("str"); } +MyVariantFull make_variant_full_complex() { return std::complex(1., 0.); } struct VariantHolder { MyVariant variant; @@ -68,7 +77,12 @@ BOOST_PYTHON_MODULE(@MODNAME@) { typedef eigenpy::VariantConverter ConverterFull; ConverterFull::registration(); - bp::def("make_variant_full", make_variant_full); + bp::def("make_variant_full_none", make_variant_full_none); + bp::def("make_variant_full_float", make_variant_full_float); + bp::def("make_variant_full_int", make_variant_full_int); + bp::def("make_variant_full_bool", make_variant_full_bool); + bp::def("make_variant_full_str", make_variant_full_str); + bp::def("make_variant_full_complex", make_variant_full_complex); boost::python::class_("VariantFullHolder", bp::init<>()) .add_property("variant",