diff options
author | Bastien Montagne <bastien@blender.org> | 2021-06-22 18:00:18 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-06-22 18:00:18 +0300 |
commit | feaf309de742a92e158cd123b3a584915de0ac4d (patch) | |
tree | a856c8f5522de1f1c5c59be8f887135fdb65fe39 /source/blender/blenlib/tests | |
parent | f4e3b1e5732ca8413a47dfdb93ae1227bb14f9dc (diff) |
Add initial `BLI_math_time` with a 'seconds decompose' function.
Allows to decompose a given amount of seconds into a random set of
days/hours/minutes/seconds/milliseconds values.
Also add matching test.
Differential Revision: https://developer.blender.org/D11581
Diffstat (limited to 'source/blender/blenlib/tests')
-rw-r--r-- | source/blender/blenlib/tests/BLI_math_time_test.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_math_time_test.cc b/source/blender/blenlib/tests/BLI_math_time_test.cc new file mode 100644 index 00000000000..4743c11b95f --- /dev/null +++ b/source/blender/blenlib/tests/BLI_math_time_test.cc @@ -0,0 +1,35 @@ +/* Apache License, Version 2.0 */ + +#include "testing/testing.h" + +#include "BLI_math.h" + +TEST(math_time, SecondsExplode) +{ + const double seconds = 2.0 * SECONDS_IN_DAY + 13.0 * SECONDS_IN_HOUR + 33.0 * SECONDS_IN_MINUTE + + 9.0 + 369.0 * SECONDS_IN_MILLISECONDS; + const double epsilon = 1e-8; + + double r_days, r_hours, r_minutes, r_seconds, r_milliseconds; + + BLI_math_time_seconds_decompose( + seconds, &r_days, &r_hours, &r_minutes, &r_seconds, &r_milliseconds); + EXPECT_NEAR(2.0, r_days, epsilon); + EXPECT_NEAR(13.0, r_hours, epsilon); + EXPECT_NEAR(33.0, r_minutes, epsilon); + EXPECT_NEAR(9.0, r_seconds, epsilon); + EXPECT_NEAR(369.0, r_milliseconds, epsilon); + + BLI_math_time_seconds_decompose(seconds, NULL, &r_hours, &r_minutes, &r_seconds, NULL); + EXPECT_NEAR(61.0, r_hours, epsilon); + EXPECT_NEAR(33.0, r_minutes, epsilon); + EXPECT_NEAR(9.369, r_seconds, epsilon); + + BLI_math_time_seconds_decompose(seconds, NULL, NULL, NULL, &r_seconds, NULL); + EXPECT_NEAR(seconds, r_seconds, epsilon); + + BLI_math_time_seconds_decompose(seconds, &r_days, NULL, &r_minutes, NULL, &r_milliseconds); + EXPECT_NEAR(2.0, r_days, epsilon); + EXPECT_NEAR(813.0, r_minutes, epsilon); + EXPECT_NEAR(9369.0, r_milliseconds, epsilon); +} |