From af1af7d5b73e4b1e1d0bf30bdabe4374857bbf6c Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Thu, 6 Jun 2019 21:37:30 -0400 Subject: [PATCH] Unit tests to parse floating point numbers in E-notation. Issue #24 --- test/test_negative_numbers.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_negative_numbers.hpp b/test/test_negative_numbers.hpp index 668f117a..a307d559 100644 --- a/test/test_negative_numbers.hpp +++ b/test/test_negative_numbers.hpp @@ -63,3 +63,33 @@ TEST_CASE("Parse negative floats into a vector", "[positional_arguments]") { program.parse_args({"./main", "-1.001", "-2.002", "3.003"}); REQUIRE(program["number"] == std::vector{-1.001, -2.002, 3.003}); } + +TEST_CASE("Parse numbers in E notation", "[positional_arguments]") { + argparse::ArgumentParser program; + program.add_argument("--verbose", "-v") + .help("enable verbose logging") + .default_value(false) + .implicit_value(true); + + program.add_argument("number") + .help("Input number") + .action([](const std::string& value) { return std::stod(value); }); + + program.parse_args({"./main", "-1.2e3"}); + REQUIRE(program.get("number") == -1200.0); +} + +TEST_CASE("Parse numbers in E notation (capital E)", "[positional_arguments]") { + argparse::ArgumentParser program; + program.add_argument("--verbose", "-v") + .help("enable verbose logging") + .default_value(false) + .implicit_value(true); + + program.add_argument("number") + .help("Input number") + .action([](const std::string& value) { return std::stod(value); }); + + program.parse_args({"./main", "-1.32E4"}); + REQUIRE(program.get("number") == -13200.0); +}