test_chrono.cpp
Go to the documentation of this file.
1 /*
2  tests/test_chrono.cpp -- test conversions to/from std::chrono types
3 
4  Copyright (c) 2016 Trent Houliston <trent@houliston.me> and
5  Wenzel Jakob <wenzel.jakob@epfl.ch>
6 
7  All rights reserved. Use of this source code is governed by a
8  BSD-style license that can be found in the LICENSE file.
9 */
10 
11 #include <pybind11/chrono.h>
12 
13 #include "pybind11_tests.h"
14 
15 #include <chrono>
16 
18  using time_point_h = std::chrono::time_point<std::chrono::system_clock, std::chrono::hours>;
19  using time_point_m = std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>;
20  using time_point_s = std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>;
21  using time_point_ms
22  = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>;
23  using time_point_us
24  = std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>;
30 };
31 
32 TEST_SUBMODULE(chrono, m) {
33  using system_time = std::chrono::system_clock::time_point;
34  using steady_time = std::chrono::steady_clock::time_point;
35 
36  using timespan = std::chrono::duration<int64_t, std::nano>;
37  using timestamp = std::chrono::time_point<std::chrono::system_clock, timespan>;
38 
39  // test_chrono_system_clock
40  // Return the current time off the wall clock
41  m.def("test_chrono1", []() { return std::chrono::system_clock::now(); });
42 
43  // test_chrono_system_clock_roundtrip
44  // Round trip the passed in system clock time
45  m.def("test_chrono2", [](system_time t) { return t; });
46 
47  // test_chrono_duration_roundtrip
48  // Round trip the passed in duration
49  m.def("test_chrono3", [](std::chrono::system_clock::duration d) { return d; });
50 
51  // test_chrono_duration_subtraction_equivalence
52  // Difference between two passed in time_points
53  m.def("test_chrono4", [](system_time a, system_time b) { return a - b; });
54 
55  // test_chrono_steady_clock
56  // Return the current time off the steady_clock
57  m.def("test_chrono5", []() { return std::chrono::steady_clock::now(); });
58 
59  // test_chrono_steady_clock_roundtrip
60  // Round trip a steady clock timepoint
61  m.def("test_chrono6", [](steady_time t) { return t; });
62 
63  // test_floating_point_duration
64  // Roundtrip a duration in microseconds from a float argument
65  m.def("test_chrono7", [](std::chrono::microseconds t) { return t; });
66  // Float durations (issue #719)
67  m.def("test_chrono_float_diff",
68  [](std::chrono::duration<float> a, std::chrono::duration<float> b) { return a - b; });
69 
70  m.def("test_nano_timepoint",
71  [](timestamp start, timespan delta) -> timestamp { return start + delta; });
72 
73  // Test different resolutions
74  py::class_<different_resolutions>(m, "different_resolutions")
75  .def(py::init<>())
76  .def_readwrite("timestamp_h", &different_resolutions::timestamp_h)
77  .def_readwrite("timestamp_m", &different_resolutions::timestamp_m)
78  .def_readwrite("timestamp_s", &different_resolutions::timestamp_s)
79  .def_readwrite("timestamp_ms", &different_resolutions::timestamp_ms)
80  .def_readwrite("timestamp_us", &different_resolutions::timestamp_us);
81 }
Matrix3f m
std::chrono::time_point< std::chrono::system_clock, std::chrono::minutes > time_point_m
Definition: test_chrono.cpp:19
Scalar * b
Definition: benchVecAdd.cpp:17
time_point_m timestamp_m
Definition: test_chrono.cpp:26
time_point_us timestamp_us
Definition: test_chrono.cpp:29
std::chrono::time_point< std::chrono::system_clock, std::chrono::hours > time_point_h
Definition: test_chrono.cpp:18
TEST_SUBMODULE(chrono, m)
Definition: test_chrono.cpp:32
std::chrono::time_point< std::chrono::system_clock, std::chrono::microseconds > time_point_us
Definition: test_chrono.cpp:24
std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > time_point_ms
Definition: test_chrono.cpp:22
time_point_h timestamp_h
Definition: test_chrono.cpp:25
time_point_s timestamp_s
Definition: test_chrono.cpp:27
std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds > time_point_s
Definition: test_chrono.cpp:20
time_point_ms timestamp_ms
Definition: test_chrono.cpp:28
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:45