Skip to content

Commit

Permalink
Added Helper function isTimeString to Python (#471)
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde authored Jul 21, 2022
1 parent 6fbc966 commit 577fc02
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
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

0 comments on commit 577fc02

Please sign in to comment.