diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index ed4872a7a..c724e5d04 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -88,7 +88,6 @@ if (PYTHONLIBS_FOUND) # Add the Python tests set(python_tests python_TEST - SignalStats_TEST SphericalCoordinates_TEST Vector3Stats_TEST ) diff --git a/src/python_pybind11/CMakeLists.txt b/src/python_pybind11/CMakeLists.txt index 73e9232fc..29f23dc02 100644 --- a/src/python_pybind11/CMakeLists.txt +++ b/src/python_pybind11/CMakeLists.txt @@ -28,6 +28,7 @@ if (${pybind11_FOUND}) src/RollingMean.cc src/RotationSpline.cc src/SemanticVersion.cc + src/SignalStats.cc src/Spline.cc src/StopWatch.cc src/Temperature.cc @@ -111,6 +112,7 @@ if (${pybind11_FOUND}) RollingMean_TEST RotationSpline_TEST SemanticVersion_TEST + SignalStats_TEST Sphere_TEST Spline_TEST StopWatch_TEST diff --git a/src/python_pybind11/src/SignalStats.cc b/src/python_pybind11/src/SignalStats.cc new file mode 100644 index 000000000..69b31e661 --- /dev/null +++ b/src/python_pybind11/src/SignalStats.cc @@ -0,0 +1,551 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ +#include + +#include +#include + +#include "SignalStats.hh" +#include + +namespace ignition +{ +namespace math +{ +namespace python +{ +////////////////////////////////////////////////// +void defineMathSignalStats(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalStats; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def(py::init()) + .def("count", &Class::Count, "Get number of data points in first statistic.") + .def("reset", &Class::Reset, "Forget all previous data.") + .def("map", &Class::Map, + "Get the current values of each statistical measure, " + "stored in a map using the short name as the key.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measures.") + .def("insert_statistic", + &Class::InsertStatistic, + "Add a new type of statistic.") + .def("insert_statistics", + &Class::InsertStatistics, + "Add multiple statistics."); +} + +////////////////////////////////////////////////// +class SignalStatisticTrampoline : public ignition::math::SignalStatistic +{ +public: + SignalStatisticTrampoline() : SignalStatistic() {} + explicit SignalStatisticTrampoline(const SignalStatistic &_ss) : + SignalStatistic(_ss) {} + + // Trampoline (need one for each virtual function) + double Value() const override + { + PYBIND11_OVERLOAD_PURE( + double, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Value, + ); + } + // Trampoline (need one for each virtual function) + std::string ShortName() const override + { + PYBIND11_OVERLOAD_PURE( + std::string, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + ShortName, + ); + } + // Trampoline (need one for each virtual function) + size_t Count() const override + { + PYBIND11_OVERLOAD_PURE( + size_t, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Count, + ); + } + // Trampoline (need one for each virtual function) + void InsertData(const double _data) override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + InsertData, + _data // Argument(s) (...) + ); + } + // Trampoline (need one for each virtual function) + void Reset() override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Reset, + ); + } +}; + +////////////////////////////////////////////////// +void defineMathSignalStatistic(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalStatistic; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def(py::init()) + .def("value", + &Class::Value, + "Get a short version of the name of this statistical measure.") + .def("short_name", + &Class::ShortName, + "Get a short version of the name of this statistical measure.") + .def("count", + &Class::Count, + "Get number of data points in measurement.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measure.") + .def("reset", + &Class::Reset, + "Forget all previous data."); +} + +////////////////////////////////////////////////// +class SignalVarianceTrampoline : public ignition::math::SignalVariance { +public: + // Inherit the constructors + SignalVarianceTrampoline(){} + + // Trampoline (need one for each virtual function) + double Value() const override + { + PYBIND11_OVERLOAD_PURE( + double, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Value, + ); + } + // Trampoline (need one for each virtual function) + std::string ShortName() const override + { + PYBIND11_OVERLOAD_PURE( + std::string, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + ShortName, + ); + } + // Trampoline (need one for each virtual function) + void InsertData(const double _data) override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + InsertData, + _data // Argument(s) (...) + ); + } +}; + +////////////////////////////////////////////////// +void defineMathSignalVariance(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalVariance; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def("reset", + &Class::Reset, + "Forget all previous data.") + .def("count", + &Class::Count, + "Get number of data points in measurement.") + .def("value", + &Class::Value, + "Get a short version of the name of this statistical measure.") + .def("short_name", + &Class::ShortName, + "Get a short version of the name of this statistical measure.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measure."); +} + +////////////////////////////////////////////////// +class SignalMaximumTrampoline : public ignition::math::SignalMaximum +{ +public: + // Inherit the constructors + SignalMaximumTrampoline(){} + + // Trampoline (need one for each virtual function) + double Value() const override + { + PYBIND11_OVERLOAD_PURE( + double, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Value, + ); + } + // Trampoline (need one for each virtual function) + std::string ShortName() const override + { + PYBIND11_OVERLOAD_PURE( + std::string, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + ShortName, + ); + } + // Trampoline (need one for each virtual function) + void InsertData(const double _data) override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + InsertData, + _data // Argument(s) (...) + ); + } +}; + +////////////////////////////////////////////////// +void defineMathSignalMaximum(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalMaximum; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def("reset", + &Class::Reset, + "Forget all previous data.") + .def("count", + &Class::Count, + "Get number of data points in measurement.") + .def("value", + &Class::Value, + "Get a short version of the name of this statistical measure.") + .def("short_name", + &Class::ShortName, + "Get a short version of the name of this statistical measure.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measure."); +} + +////////////////////////////////////////////////// +class SignalMinimumTrampoline : public ignition::math::SignalMinimum +{ +public: + // Inherit the constructors + SignalMinimumTrampoline(){} + + // Trampoline (need one for each virtual function) + double Value() const override + { + PYBIND11_OVERLOAD_PURE( + double, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Value, + ); + } + // Trampoline (need one for each virtual function) + std::string ShortName() const override + { + PYBIND11_OVERLOAD_PURE( + std::string, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + ShortName, + ); + } + // Trampoline (need one for each virtual function) + void InsertData(const double _data) override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + InsertData, + _data // Argument(s) (...) + ); + } +}; + +////////////////////////////////////////////////// +void defineMathSignalMinimum(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalMinimum; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def("reset", + &Class::Reset, + "Forget all previous data.") + .def("count", + &Class::Count, + "Get number of data points in measurement.") + .def("value", + &Class::Value, + "Get a short version of the name of this statistical measure.") + .def("short_name", + &Class::ShortName, + "Get a short version of the name of this statistical measure.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measure."); +} + +////////////////////////////////////////////////// +class SignalMeanTrampoline : public ignition::math::SignalMean +{ +public: + // Inherit the constructors + SignalMeanTrampoline(){} + + // Trampoline (need one for each virtual function) + double Value() const override + { + PYBIND11_OVERLOAD_PURE( + double, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Value, + ); + } + // Trampoline (need one for each virtual function) + std::string ShortName() const override + { + PYBIND11_OVERLOAD_PURE( + std::string, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + ShortName, + ); + } + // Trampoline (need one for each virtual function) + void InsertData(const double _data) override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + InsertData, + _data // Argument(s) (...) + ); + } +}; + +////////////////////////////////////////////////// +void defineMathSignalMean(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalMean; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def("reset", + &Class::Reset, + "Forget all previous data.") + .def("count", + &Class::Count, + "Get number of data points in measurement.") + .def("value", + &Class::Value, + "Get a short version of the name of this statistical measure.") + .def("short_name", + &Class::ShortName, + "Get a short version of the name of this statistical measure.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measure."); +} + +////////////////////////////////////////////////// +class SignalRootMeanSquareTrampoline : + public ignition::math::SignalRootMeanSquare +{ +public: + // Inherit the constructors + SignalRootMeanSquareTrampoline(){} + + // Trampoline (need one for each virtual function) + double Value() const override + { + PYBIND11_OVERLOAD_PURE( + double, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Value, + ); + } + // Trampoline (need one for each virtual function) + std::string ShortName() const override + { + PYBIND11_OVERLOAD_PURE( + std::string, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + ShortName + ); + } + // Trampoline (need one for each virtual function) + void InsertData(const double _data) override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + InsertData, + _data // Argument(s) (...) + ); + } +}; + +////////////////////////////////////////////////// +void defineMathSignalRootMeanSquare(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalRootMeanSquare; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def("reset", + &Class::Reset, + "Forget all previous data.") + .def("count", + &Class::Count, + "Get number of data points in measurement.") + .def("value", + &Class::Value, + "Get a short version of the name of this statistical measure.") + .def("short_name", + &Class::ShortName, + "Get a short version of the name of this statistical measure.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measure."); +} + +////////////////////////////////////////////////// +class SignalMaxAbsoluteValueTrampoline : + public ignition::math::SignalMaxAbsoluteValue +{ +public: + // Inherit the constructors + SignalMaxAbsoluteValueTrampoline(){} + + // Trampoline (need one for each virtual function) + double Value() const override + { + PYBIND11_OVERLOAD_PURE( + double, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + Value, + ); + } + // Trampoline (need one for each virtual function) + std::string ShortName() const override + { + PYBIND11_OVERLOAD_PURE( + std::string, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + ShortName, + ); + } + // Trampoline (need one for each virtual function) + void InsertData(const double _data) override + { + PYBIND11_OVERLOAD_PURE( + void, // Return type (ret_type) + ignition::math::SignalStatistic, // Parent class (cname) + // Name of function in C++ (must match Python name) (fn) + InsertData, + _data // Argument(s) (...) + ); + } +}; + +////////////////////////////////////////////////// +void defineMathSignalMaxAbsoluteValue(py::module &m, const std::string &typestr) +{ + using Class = ignition::math::SignalMaxAbsoluteValue; + std::string pyclass_name = typestr; + py::class_(m, + pyclass_name.c_str(), + py::buffer_protocol(), + py::dynamic_attr()) + .def(py::init<>()) + .def("reset", + &Class::Reset, + "Forget all previous data.") + .def("count", + &Class::Count, + "Get number of data points in measurement.") + .def("value", + &Class::Value, + "Get a short version of the name of this statistical measure.") + .def("short_name", + &Class::ShortName, + "Get a short version of the name of this statistical measure.") + .def("insert_data", + &Class::InsertData, + "Add a new sample to the statistical measure."); +} +} // namespace python +} // namespace math +} // namespace ignition diff --git a/src/python_pybind11/src/SignalStats.hh b/src/python_pybind11/src/SignalStats.hh new file mode 100644 index 000000000..7e92e1940 --- /dev/null +++ b/src/python_pybind11/src/SignalStats.hh @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#ifndef IGNITION_MATH_PYTHON__SIGNALSTATS_HH_ +#define IGNITION_MATH_PYTHON__SIGNALSTATS_HH_ + +#include +#include + +namespace py = pybind11; + +namespace ignition +{ +namespace math +{ +namespace python +{ +/// Define a pybind11 wrapper for an ignition::math::SignalStats +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalStats(py::module &m, const std::string &typestr); + +/// Define a pybind11 wrapper for an ignition::math::SignalStatistic +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalStatistic(py::module &m, const std::string &typestr); + +/// Define a pybind11 wrapper for an ignition::math::SignalMaximum +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalMaximum(py::module &m, const std::string &typestr); + +/// Define a pybind11 wrapper for an ignition::math::SignalMinimum +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalMinimum(py::module &m, const std::string &typestr); + +/// Define a pybind11 wrapper for an ignition::math::SignalVariance +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalVariance(py::module &m, const std::string &typestr); + +/// Define a pybind11 wrapper for an ignition::math::SignalMaxAbsoluteValue +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalMaxAbsoluteValue( + py::module &m, const std::string &typestr); + +/// Define a pybind11 wrapper for an ignition::math::SignalRootMeanSquare +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalRootMeanSquare(py::module &m, const std::string &typestr); + +/// Define a pybind11 wrapper for an ignition::math::SignalMean +/** + * \param[in] module a pybind11 module to add the definition to + * \param[in] typestr name of the type used by Python + */ +void defineMathSignalMean(py::module &m, const std::string &typestr); +} // namespace python +} // namespace math +} // namespace ignition + +#endif // IGNITION_MATH_PYTHON__SIGNALSTATS_HH_ diff --git a/src/python_pybind11/src/_ignition_math_pybind11.cc b/src/python_pybind11/src/_ignition_math_pybind11.cc index 1e1aa8b4b..61d4dd2a6 100644 --- a/src/python_pybind11/src/_ignition_math_pybind11.cc +++ b/src/python_pybind11/src/_ignition_math_pybind11.cc @@ -42,6 +42,7 @@ #include "RollingMean.hh" #include "RotationSpline.hh" #include "SemanticVersion.hh" +#include "SignalStats.hh" #include "Sphere.hh" #include "Spline.hh" #include "StopWatch.hh" @@ -89,6 +90,17 @@ PYBIND11_MODULE(math, m) ignition::math::python::defineMathRollingMean(m, "RollingMean"); + ignition::math::python::defineMathSignalStats(m, "SignalStats"); + ignition::math::python::defineMathSignalStatistic(m, "SignalStatistic"); + ignition::math::python::defineMathSignalVariance(m, "SignalVariance"); + ignition::math::python::defineMathSignalMaximum(m, "SignalMaximum"); + ignition::math::python::defineMathSignalMinimum(m, "SignalMinimum"); + ignition::math::python::defineMathSignalMaxAbsoluteValue( + m, "SignalMaxAbsoluteValue"); + ignition::math::python::defineMathSignalRootMeanSquare( + m, "SignalRootMeanSquare"); + ignition::math::python::defineMathSignalMean(m, "SignalMean"); + ignition::math::python::defineMathRotationSpline(m, "RotationSpline"); ignition::math::python::defineMathSemanticVersion(m, "SemanticVersion"); diff --git a/src/python/SignalStats_TEST.py b/src/python_pybind11/test/SignalStats_TEST.py similarity index 86% rename from src/python/SignalStats_TEST.py rename to src/python_pybind11/test/SignalStats_TEST.py index e8497e6d2..26e4e4974 100644 --- a/src/python/SignalStats_TEST.py +++ b/src/python_pybind11/test/SignalStats_TEST.py @@ -372,7 +372,7 @@ def test_signal_variance_random_values(self): def test_signal_stats_constructor(self): # Constructor stats = SignalStats() - self.assertTrue(stats.map().empty()) + self.assertTrue(len(stats.map()) == 0) self.assertEqual(stats.count(), 0) stats2 = SignalStats(stats) @@ -380,110 +380,111 @@ def test_signal_stats_constructor(self): # reset stats.reset() - self.assertTrue(stats.map().empty()) + self.assertTrue(len(stats.map()) == 0) self.assertEqual(stats.count(), 0) def test_01_signal_stats_intern_statistic(self): # insert static stats = SignalStats() - self.assertTrue(stats.map().empty()) + self.assertTrue(len(stats.map()) == 0) self.assertTrue(stats.insert_statistic("max")) self.assertFalse(stats.insert_statistic("max")) - self.assertFalse(stats.map().empty()) + self.assertFalse(len(stats.map()) == 0) self.assertTrue(stats.insert_statistic("maxAbs")) self.assertFalse(stats.insert_statistic("maxAbs")) - self.assertFalse(stats.map().empty()) + self.assertFalse(len(stats.map()) == 0) self.assertTrue(stats.insert_statistic("mean")) self.assertFalse(stats.insert_statistic("mean")) - self.assertFalse(stats.map().empty()) + self.assertFalse(len(stats.map()) == 0) self.assertTrue(stats.insert_statistic("min")) self.assertFalse(stats.insert_statistic("min")) - self.assertFalse(stats.map().empty()) + self.assertFalse(len(stats.map()) == 0) self.assertTrue(stats.insert_statistic("rms")) self.assertFalse(stats.insert_statistic("rms")) - self.assertFalse(stats.map().empty()) + self.assertFalse(len(stats.map()) == 0) self.assertTrue(stats.insert_statistic("var")) self.assertFalse(stats.insert_statistic("var")) - self.assertFalse(stats.map().empty()) + self.assertFalse(len(stats.map()) == 0) self.assertFalse(stats.insert_statistic("FakeStatistic")) # map with no data map = stats.map() - self.assertFalse(map.empty()) - self.assertEqual(map.size(), 6) - self.assertEqual(map.count("max"), 1) - self.assertEqual(map.count("maxAbs"), 1) - self.assertEqual(map.count("mean"), 1) - self.assertEqual(map.count("min"), 1) - self.assertEqual(map.count("rms"), 1) - self.assertEqual(map.count("var"), 1) - self.assertEqual(map.count("FakeStatistic"), 0) + self.assertFalse(len(map) == 0) + self.assertEqual(len(map), 6) + + self.assertEqual("max" in map.keys(), 1) + self.assertEqual("maxAbs" in map.keys(), 1) + self.assertEqual("mean" in map.keys(), 1) + self.assertEqual("min" in map.keys(), 1) + self.assertEqual("rms" in map.keys(), 1) + self.assertEqual("var" in map.keys(), 1) + self.assertEqual("FakeStatistic" in map.keys(), 0) stats2 = SignalStats(stats) map2 = stats2.map() - self.assertFalse(map2.empty()) - self.assertEqual(map.size(), map2.size()) - self.assertEqual(map.count("max"), map2.count("max")) - self.assertEqual(map.count("maxAbs"), map2.count("maxAbs")) - self.assertEqual(map.count("mean"), map2.count("mean")) - self.assertEqual(map.count("min"), map2.count("min")) - self.assertEqual(map.count("rms"), map2.count("rms")) - self.assertEqual(map.count("var"), map2.count("var")) - self.assertEqual(map.count("FakeStatistic"), - map2.count("FakeStatistic")) + self.assertFalse(len(map2) == 0) + self.assertEqual(len(map), len(map2)) + self.assertEqual("max" in map.keys(), "max" in map2.keys()) + self.assertEqual("maxAbs" in map.keys(), "maxAbs" in map2.keys()) + self.assertEqual("mean" in map.keys(), "mean" in map2.keys()) + self.assertEqual("min" in map.keys(), "min" in map2.keys()) + self.assertEqual("rms" in map.keys(), "rms" in map2.keys()) + self.assertEqual("var" in map.keys(), "var" in map2.keys()) + self.assertEqual("FakeStatistic" in map.keys(), + "FakeStatistic" in map2.keys()) def test_02_signal_stats_intern_statistic(self): # insert statics stats = SignalStats() self.assertFalse(stats.insert_statistics("")) - self.assertTrue(stats.map().empty()) + self.assertTrue(len(stats.map()) == 0) self.assertTrue(stats.insert_statistics("maxAbs,rms")) - self.assertEqual(stats.map().size(), 2) + self.assertEqual(len(stats.map()), 2) self.assertFalse(stats.insert_statistics("maxAbs,rms")) self.assertFalse(stats.insert_statistics("maxAbs")) self.assertFalse(stats.insert_statistics("rms")) - self.assertEqual(stats.map().size(), 2) + self.assertEqual(len(stats.map()), 2) self.assertFalse(stats.insert_statistics("mean,FakeStatistic")) - self.assertEqual(stats.map().size(), 3) + self.assertEqual(len(stats.map()), 3) self.assertFalse(stats.insert_statistics("var,FakeStatistic")) - self.assertEqual(stats.map().size(), 4) + self.assertEqual(len(stats.map()), 4) self.assertFalse(stats.insert_statistics("max,FakeStatistic")) - self.assertEqual(stats.map().size(), 5) + self.assertEqual(len(stats.map()), 5) self.assertFalse(stats.insert_statistics("min,FakeStatistic")) - self.assertEqual(stats.map().size(), 6) + self.assertEqual(len(stats.map()), 6) self.assertFalse(stats.insert_statistics("FakeStatistic")) - self.assertEqual(stats.map().size(), 6) + self.assertEqual(len(stats.map()), 6) # map with no data map = stats.map() - self.assertFalse(map.empty()) - self.assertEqual(map.size(), 6) - self.assertEqual(map.count("max"), 1) - self.assertEqual(map.count("maxAbs"), 1) - self.assertEqual(map.count("mean"), 1) - self.assertEqual(map.count("min"), 1) - self.assertEqual(map.count("rms"), 1) - self.assertEqual(map.count("var"), 1) - self.assertEqual(map.count("FakeStatistic"), 0) + self.assertFalse(len(map) == 0) + self.assertEqual(len(map), 6) + self.assertEqual("max" in map.keys(), 1) + self.assertEqual("maxAbs" in map.keys(), 1) + self.assertEqual("mean" in map.keys(), 1) + self.assertEqual("min" in map.keys(), 1) + self.assertEqual("rms" in map.keys(), 1) + self.assertEqual("var" in map.keys(), 1) + self.assertEqual("FakeStatistic" in map.keys(), 0) def test_signal_stats_alternating_values(self): # Add some statistics stats = SignalStats() self.assertTrue(stats.insert_statistics("max,maxAbs,mean,min,rms")) - self.assertEqual(stats.map().size(), 5) + self.assertEqual(len(stats.map()), 5) # No data yet self.assertEqual(stats.count(), 0) @@ -505,7 +506,7 @@ def test_signal_stats_alternating_values(self): copy = SignalStats(stats) self.assertEqual(copy.count(), 2) map = stats.map() - self.assertEqual(map.size(), 5) + self.assertEqual(len(map), 5) self.assertAlmostEqual(map["max"], value) self.assertAlmostEqual(map["maxAbs"], value) self.assertAlmostEqual(map["min"], -value) @@ -513,7 +514,7 @@ def test_signal_stats_alternating_values(self): self.assertAlmostEqual(map["mean"], 0.0) stats.reset() - self.assertEqual(stats.map().size(), 5) + self.assertEqual(len(stats.map()), 5) self.assertEqual(stats.count(), 0) map = stats.map() self.assertAlmostEqual(map["max"], 0.0)