Feat: Floor (#309)

* feat: first draft floor

* apply review feedback and move to desired files

* implement floor considering float types

* reduce code duplication

* apply review feedback and improve docstring

* enable static floor tests for gcc only

* Use recommended feature-test macro

* add floor runtime unittests

* apply review feedback

* make lambda const
This commit is contained in:
Markus Hofbauer
2021-11-13 12:17:43 +01:00
committed by GitHub
parent 331024a199
commit e82bfa23a5
3 changed files with 107 additions and 5 deletions
+42
View File
@@ -24,10 +24,12 @@
#include <units/isq/si/area.h>
#include <units/isq/si/length.h>
#include <units/isq/si/volume.h>
#include <units/isq/si/time.h>
#include <catch2/catch.hpp>
#include <limits>
using namespace units;
using namespace units::isq;
using namespace units::isq::si;
// classical
@@ -108,6 +110,46 @@ TEST_CASE("numeric_limits functions", "[limits]")
}
}
TEST_CASE("floor functions", "[floor]")
{
SECTION ("floor 1 second with target unit second should be 1 second") {
REQUIRE(floor<si::second>(1_q_s) == 1_q_s);
}
SECTION ("floor 1000 milliseconds with target unit second should be 1 second") {
REQUIRE(floor<si::second>(1000_q_ms) == 1_q_s);
}
SECTION ("floor 1001 milliseconds with target unit second should be 1 second") {
REQUIRE(floor<si::second>(1001_q_ms) == 1_q_s);
}
SECTION ("floor 1999 milliseconds with target unit second should be 1 second") {
REQUIRE(floor<si::second>(1999_q_ms) == 1_q_s);
}
SECTION ("floor -1000 milliseconds with target unit second should be -1 second") {
REQUIRE(floor<si::second>(-1000_q_ms) == -1_q_s);
}
SECTION ("floor -999 milliseconds with target unit second should be -1 second") {
REQUIRE(floor<si::second>(-999_q_ms) == -1_q_s);
}
SECTION ("floor 1.3 seconds with target unit second should be 1 second") {
REQUIRE(floor<si::second>(1.3_q_s) == 1_q_s);
}
SECTION ("floor -1.3 seconds with target unit second should be -1 second") {
REQUIRE(floor<si::second>(-1.3_q_s) == -2_q_s);
}
SECTION ("floor 1001. milliseconds with target unit second should be 1 second") {
REQUIRE(floor<si::second>(1001._q_ms) == 1_q_s);
}
SECTION ("floor 1999. milliseconds with target unit second should be 1 second") {
REQUIRE(floor<si::second>(1999._q_ms) == 1_q_s);
}
SECTION ("floor -1000. milliseconds with target unit second should be -1 second") {
REQUIRE(floor<si::second>(-1000._q_ms) == -1_q_s);
}
SECTION ("floor -999. milliseconds with target unit second should be -1 second") {
REQUIRE(floor<si::second>(-999._q_ms) == -1_q_s);
}
}
TEMPLATE_TEST_CASE_SIG("pow<N>() implementation exponentiates values to power N", "[math][pow][exp]",
(std::intmax_t N, N), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25)
{