increase coverage and fix noexcept (#375)

This commit is contained in:
Hans Dembinski 2022-12-23 01:21:39 +01:00 committed by GitHub
parent 3804826411
commit 72064c642a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View File

@ -61,7 +61,7 @@ class confidence_level;
class deviation { class deviation {
public: public:
/// constructor from units of standard deviations /// constructor from units of standard deviations
explicit deviation(double d) noexcept : d_{d} { explicit deviation(double d) : d_{d} {
if (d <= 0) if (d <= 0)
BOOST_THROW_EXCEPTION(std::invalid_argument("scaling factor must be positive")); BOOST_THROW_EXCEPTION(std::invalid_argument("scaling factor must be positive"));
} }
@ -93,7 +93,7 @@ private:
class confidence_level { class confidence_level {
public: public:
/// constructor from confidence level (a probability) /// constructor from confidence level (a probability)
explicit confidence_level(double cl) noexcept : cl_{cl} { explicit confidence_level(double cl) : cl_{cl} {
if (cl <= 0 || cl >= 1) if (cl <= 0 || cl >= 1)
BOOST_THROW_EXCEPTION(std::invalid_argument("0 < cl < 1 is required")); BOOST_THROW_EXCEPTION(std::invalid_argument("0 < cl < 1 is required"));
} }

View File

@ -45,6 +45,7 @@ void run_tests() {
BOOST_TEST_EQ(f.successes(), 1); BOOST_TEST_EQ(f.successes(), 1);
BOOST_TEST_EQ(f.failures(), 1); BOOST_TEST_EQ(f.failures(), 1);
BOOST_TEST_EQ(str(f), "fraction(1, 1)"s); BOOST_TEST_EQ(str(f), "fraction(1, 1)"s);
BOOST_TEST_EQ(str(f, 20), "fraction(1, 1) "s);
} }
{ {

View File

@ -26,5 +26,13 @@ int main() {
BOOST_TEST_IS_CLOSE(static_cast<double>(deviation(cl3)), 3, 1e-8); BOOST_TEST_IS_CLOSE(static_cast<double>(deviation(cl3)), 3, 1e-8);
} }
// invalid values
{
BOOST_TEST_THROWS((void)deviation{-0.5}, std::invalid_argument);
BOOST_TEST_THROWS((void)confidence_level{-0.1}, std::invalid_argument);
BOOST_TEST_THROWS((void)confidence_level{0}, std::invalid_argument);
BOOST_TEST_THROWS((void)confidence_level{1.1}, std::invalid_argument);
}
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -16,7 +16,7 @@ from pathlib import Path
import os import os
import sys import sys
LCOV_VERSION = "1.15" LCOV_VERSION = "1.16"
gcov = os.environ.get("GCOV", "gcov") gcov = os.environ.get("GCOV", "gcov")