X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/18da30894e88a2ab587f793e3ec500b1842c0966..cd5185ae774cc99650b6cae2dca17b6062accea3:/src/xbt/xbt_str_test.cpp?ds=sidebyside diff --git a/src/xbt/xbt_str_test.cpp b/src/xbt/xbt_str_test.cpp index 22ee6f9194..1b98a83ca8 100644 --- a/src/xbt/xbt_str_test.cpp +++ b/src/xbt/xbt_str_test.cpp @@ -1,15 +1,16 @@ /* xbt_str.cpp - various helping functions to deal with strings */ -/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "xbt/parse_units.hpp" #include "xbt/str.h" #include "simgrid/Exception.hpp" -#include "catch.hpp" +#include "src/3rd-party/catch.hpp" #include #include @@ -52,4 +53,24 @@ TEST_CASE("xbt::str: String Handling", "xbt_str") test_parse_error(xbt_str_parse_double, "Parse '' as a double", ""); test_parse_error(xbt_str_parse_double, "Parse cruft as a double", "cruft"); } + + SECTION("Test the parsing-with-units functions") + { + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1.0", "") == std::vector{1e0}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1.0,2.0", "") == std::vector{1e0, 2e0}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1.0,2.0,3.0", "") == std::vector{1e0, 2e0, 3e0}); + + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1", "") == std::vector{1e0}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1,2", "") == std::vector{1.0, 2.0}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1,2,3", "") == std::vector{1.0, 2.0, 3.0}); + + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1.0f", "") == std::vector{1e0}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1.0kf,2.0Mf", "") == std::vector{1e3, 2e6}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1.0Gf,2.0Tf,3.0Pf", "") == + std::vector{1e9, 2e12, 3e15}); + + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1f", "") == std::vector{1e0}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1kf,2Gf", "") == std::vector{1e3, 2e9}); + REQUIRE(xbt_parse_get_all_speeds(__FILE__, __LINE__, "1Ef,2Zf,3Yf", "") == std::vector{1e18, 2e21, 3e24}); + } }