Skip to content

Commit

Permalink
Unit tests to parse floating point numbers in E-notation. Issue #24
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ranav committed Jun 7, 2019
1 parent 6e69548 commit af1af7d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/test_negative_numbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>{-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<double>("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<double>("number") == -13200.0);
}

0 comments on commit af1af7d

Please sign in to comment.