Commit 87480d42 authored by Lukas Weber's avatar Lukas Weber
Browse files

using a unit test to find a bug in the duration parser B)

parent ade03b37
......@@ -19,3 +19,4 @@ should_install = not meson.is_subproject()
loadleveller_deps = [ fmt_dep, yamlcpp_dep, mpi_dep, hdf5_lib ]
subdir('src')
subdir('test')
......@@ -26,7 +26,7 @@ enum {
// parses the duration '[[hours:]minutes:]seconds' into seconds
// replace as soon as there is an alternative
static double parse_duration(std::string str) {
static int parse_duration(const std::string &str) {
size_t idx;
try {
......@@ -46,7 +46,7 @@ static double parse_duration(std::string str) {
throw std::runtime_error{"minutes"};
}
return 24 * 60 * i1 + 60 * i2 + i3;
return 60 * 60 * i1 + 60 * i2 + i3;
} else {
throw std::runtime_error{"hours"};
}
......
#include "runner.cpp"
int main() {
using namespace loadl;
if(parse_duration("20") != 20) {
return 1;
}
if(parse_duration("10:03") != 10*60+3) {
return 2;
}
if(parse_duration("24:06:10") != 60*60*24+60*6+10) {
return 3;
}
return 0;
}
t1 = executable('test_duration_parser', 'duration_parser.cpp',
dependencies : loadleveller_dep,
include_directories : include_directories('../src')
)
test('test duration parser', t1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment