Debian Codegraph @

src/pycolmap/util/timestamp_test.py

raw
1 import pytest
2
3 import pycolmap
4
5
6 def test_timestamp_from_seconds():
7 # Timestamps are integer nanoseconds.
8 assert pycolmap.timestamp_from_seconds(1.5) == 1_500_000_000
9 # Rounds to the nearest nanosecond.
10 assert pycolmap.timestamp_from_seconds(1e-9) == 1
11 assert pycolmap.timestamp_from_seconds(0.4e-9) == 0
12
13
14 def test_seconds_from_timestamp():
15 assert pycolmap.seconds_from_timestamp(1_500_000_000) == pytest.approx(1.5)
16 assert pycolmap.seconds_from_timestamp(0) == 0.0
17
18
19 def test_timestamp_roundtrip():
20 for seconds in [0.0, 0.001, 1.25, 10.0]:
21 t = pycolmap.timestamp_from_seconds(seconds)
22 assert pycolmap.seconds_from_timestamp(t) == pytest.approx(seconds)
23
24
25 def test_timestamp_diff_seconds():
26 t0 = pycolmap.timestamp_from_seconds(1.0)
27 t1 = pycolmap.timestamp_from_seconds(2.5)
28 assert pycolmap.timestamp_diff_seconds(t1, t0) == pytest.approx(1.5)
29 # The difference may be negative.
30 assert pycolmap.timestamp_diff_seconds(t0, t1) == pytest.approx(-1.5)