File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #define TESTING_MAIN
2+ #ifndef __BINARY_NAME__
3+ #define __BINARY_NAME__ " test_format_elapsed_time"
4+ #endif
5+ #ifndef __BINARY_DESC__
6+ #define __BINARY_DESC__ " Unit tests for FormatElapsedTime helper (issue #351)"
7+ #endif
8+
9+ #include " testing.hpp"
10+
11+ #include " ../dynadjust/include/functions/dnatimer.hpp"
12+
13+ using dynadjust::FormatElapsedTime;
14+
15+ TEST_CASE (" Sub-second durations report milliseconds" , " [time][issue351]" ) {
16+ REQUIRE (FormatElapsedTime (0.000078 ) == " 0.078ms" );
17+ REQUIRE (FormatElapsedTime (0.0 ) == " 0.000ms" );
18+ REQUIRE (FormatElapsedTime (0.5 ) == " 500.000ms" );
19+ REQUIRE (FormatElapsedTime (0.999 ) == " 999.000ms" );
20+ }
21+
22+ TEST_CASE (" Durations between 1 and 60 seconds report seconds" , " [time][issue351]" ) {
23+ REQUIRE (FormatElapsedTime (1.0 ) == " 1.000s" );
24+ REQUIRE (FormatElapsedTime (12.580 ) == " 12.580s" );
25+ REQUIRE (FormatElapsedTime (59.999 ) == " 59.999s" );
26+ }
27+
28+ TEST_CASE (" Durations of 60 seconds or more report hh:mm:ss" , " [time][issue351]" ) {
29+ REQUIRE (FormatElapsedTime (60.0 ) == " 00:01:00" );
30+ REQUIRE (FormatElapsedTime (68.0 ) == " 00:01:08" );
31+ REQUIRE (FormatElapsedTime (139.419 ) == " 00:02:19" );
32+ REQUIRE (FormatElapsedTime (3600.0 ) == " 01:00:00" );
33+ REQUIRE (FormatElapsedTime (5841.0 ) == " 01:37:21" );
34+ REQUIRE (FormatElapsedTime (26697.777 ) == " 07:24:57" );
35+ REQUIRE (FormatElapsedTime (36000.0 ) == " 10:00:00" );
36+ }
You can’t perform that action at this time.
0 commit comments