diff options
Diffstat (limited to 'ext/pybind11/tests/test_chrono.cpp')
-rw-r--r-- | ext/pybind11/tests/test_chrono.cpp | 72 |
1 files changed, 27 insertions, 45 deletions
diff --git a/ext/pybind11/tests/test_chrono.cpp b/ext/pybind11/tests/test_chrono.cpp index fcc1b6185..195a93bba 100644 --- a/ext/pybind11/tests/test_chrono.cpp +++ b/ext/pybind11/tests/test_chrono.cpp @@ -8,58 +8,40 @@ BSD-style license that can be found in the LICENSE file. */ - #include "pybind11_tests.h" -#include "constructor_stats.h" #include <pybind11/chrono.h> -// Return the current time off the wall clock -std::chrono::system_clock::time_point test_chrono1() { - return std::chrono::system_clock::now(); -} +TEST_SUBMODULE(chrono, m) { + using system_time = std::chrono::system_clock::time_point; + using steady_time = std::chrono::steady_clock::time_point; + // test_chrono_system_clock + // Return the current time off the wall clock + m.def("test_chrono1", []() { return std::chrono::system_clock::now(); }); -// Round trip the passed in system clock time -std::chrono::system_clock::time_point test_chrono2(std::chrono::system_clock::time_point t) { - return t; -} - -// Round trip the passed in duration -std::chrono::system_clock::duration test_chrono3(std::chrono::system_clock::duration d) { - return d; -} + // test_chrono_system_clock_roundtrip + // Round trip the passed in system clock time + m.def("test_chrono2", [](system_time t) { return t; }); -// Difference between two passed in time_points -std::chrono::system_clock::duration test_chrono4(std::chrono::system_clock::time_point a, std::chrono::system_clock::time_point b) { - return a - b; -} + // test_chrono_duration_roundtrip + // Round trip the passed in duration + m.def("test_chrono3", [](std::chrono::system_clock::duration d) { return d; }); -// Return the current time off the steady_clock -std::chrono::steady_clock::time_point test_chrono5() { - return std::chrono::steady_clock::now(); -} + // test_chrono_duration_subtraction_equivalence + // Difference between two passed in time_points + m.def("test_chrono4", [](system_time a, system_time b) { return a - b; }); -// Round trip a steady clock timepoint -std::chrono::steady_clock::time_point test_chrono6(std::chrono::steady_clock::time_point t) { - return t; -} + // test_chrono_steady_clock + // Return the current time off the steady_clock + m.def("test_chrono5", []() { return std::chrono::steady_clock::now(); }); -// Roundtrip a duration in microseconds from a float argument -std::chrono::microseconds test_chrono7(std::chrono::microseconds t) { - return t; -} + // test_chrono_steady_clock_roundtrip + // Round trip a steady clock timepoint + m.def("test_chrono6", [](steady_time t) { return t; }); -// Float durations (issue #719) -std::chrono::duration<double> test_chrono_float_diff(std::chrono::duration<float> a, std::chrono::duration<float> b) { - return a - b; + // test_floating_point_duration + // Roundtrip a duration in microseconds from a float argument + m.def("test_chrono7", [](std::chrono::microseconds t) { return t; }); + // Float durations (issue #719) + m.def("test_chrono_float_diff", [](std::chrono::duration<float> a, std::chrono::duration<float> b) { + return a - b; }); } - -test_initializer chrono([] (py::module &m) { - m.def("test_chrono1", &test_chrono1); - m.def("test_chrono2", &test_chrono2); - m.def("test_chrono3", &test_chrono3); - m.def("test_chrono4", &test_chrono4); - m.def("test_chrono5", &test_chrono5); - m.def("test_chrono6", &test_chrono6); - m.def("test_chrono7", &test_chrono7); - m.def("test_chrono_float_diff", &test_chrono_float_diff); -}); |