Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Helper function isTimeString to Python #471

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/python_pybind11/src/Helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ void defineMathHelpers(py::module &m)
.def("parse_float",
&ignition::math::parseFloat,
"parse string into an float")
.def("is_time_string",
&ignition::math::isTimeString,
"An example time string is \"0 00:00:00.000\", which has the format "
"DAYS HOURS:MINUTES:SECONDS.MILLISECONDS")
.def("ign_sphere_volume",
&SphereVolume,
"Compute sphere volume")
Expand Down
51 changes: 50 additions & 1 deletion src/python_pybind11/test/Helpers_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ignition.math import (Helpers, ign_box_volume, ign_box_volume_v, ign_cylinder_volume,
ign_sphere_volume, Vector3d, equal, fixnan,
greater_or_near_equal, is_even, is_odd, is_power_of_two, isnan,
less_or_near_equal, max, mean, min,
is_time_string, less_or_near_equal, max, mean, min,
parse_float, parse_int, precision, round_up_multiple,
round_up_power_of_two, signum, sort2, sort3, variance)

Expand Down Expand Up @@ -270,6 +270,55 @@ def test_volume(self):
ign_box_volume_v(Vector3d(0.1, 0.2, 0.3)),
6)

def test_is_time_string(self):
time = "0 00:00:00.000"
self.assertTrue(is_time_string(time))

time = "10 0"
self.assertTrue(is_time_string(time))

time = "7"
self.assertTrue(is_time_string(time))

time = "7:10"
self.assertTrue(is_time_string(time))

time = "17:10"
self.assertTrue(is_time_string(time))

time = "7:10.4"
self.assertTrue(is_time_string(time))

time = "7:10.45"
self.assertTrue(is_time_string(time))

time = "7:10.456"
self.assertTrue(is_time_string(time))

time = "2 23:18:25.902"
self.assertTrue(is_time_string(time))

time = ".9"
self.assertTrue(is_time_string(time))

time = "bad time"
self.assertFalse(is_time_string(time))

time = "60"
self.assertFalse(is_time_string(time))

time = "60:12"
self.assertFalse(is_time_string(time))

time = "12:12.9999"
self.assertFalse(is_time_string(time))

time = "25:12:12.99"
self.assertFalse(is_time_string(time))

time = "999999999999999 5:12:12.5"
self.assertFalse(is_time_string(time))

def test_round_up_multiple(self):
self.assertEqual(0, round_up_multiple(0, 0))
self.assertEqual(12, round_up_multiple(12, 0))
Expand Down