feat: 💥 !data system renamed to isq::iec80000 (quantity names renamed too)

Relates to #253
This commit is contained in:
Mateusz Pusz
2021-03-19 23:04:52 +01:00
parent 0cbfcf2aa6
commit fc7b0e44e2
31 changed files with 481 additions and 416 deletions
-1
View File
@@ -26,7 +26,6 @@ find_package(Catch2 CONFIG REQUIRED)
add_executable(unit_tests_runtime
catch_main.cpp
digital_info_test.cpp
math_test.cpp
fmt_test.cpp
fmt_units_test.cpp
@@ -1,77 +0,0 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <catch2/catch.hpp>
#include <units/data/data.h>
#include <units/format.h>
#include <units/quantity_io.h>
#include <sstream>
using namespace units::data;
TEST_CASE("operator<< on a data quantity", "[text][ostream]")
{
std::stringstream stream;
SECTION("quantity with a predefined unit and prefix")
{
SECTION("named unit")
{
stream << 64_q_B;
REQUIRE(stream.str() == "64 B");
}
SECTION("prefixed coherent unit")
{
stream << 256_q_Kib;
REQUIRE(stream.str() == "256 Kib");
}
SECTION("prefixed non-coherent unit")
{
stream << 1024_q_KiB;
REQUIRE(stream.str() == "1024 KiB");
}
SECTION("other unit matching prefix")
{
stream << 8_q_Kib * 8_q_Kib / 2_q_b;
REQUIRE(stream.str() == "32 Mib");
}
SECTION("prefixed coherent unit (SI)") {
stream << 32_q_kb;
REQUIRE(stream.str() == "32 kb");
}
}
}
TEST_CASE("fmt::format on data unit symbols", "[text][fmt]")
{
SECTION("symbolrate")
{
CHECK(fmt::format("{}", 1_q_Bd) == "1 Bd");
CHECK(fmt::format("{}", 1_q_kBd) == "1 kBd");
CHECK(fmt::format("{}", 1_q_MBd) == "1 MBd");
CHECK(fmt::format("{}", 1_q_GBd) == "1 GBd");
CHECK(fmt::format("{}", 1_q_TBd) == "1 TBd");
}
}
+42 -8
View File
@@ -21,6 +21,7 @@
// SOFTWARE.
#include "units/format.h"
#include "units/isq/iec80000/iec80000.h"
#include "units/isq/si/si.h"
#include "units/isq/si/iau/iau.h"
#include "units/isq/si/imperial/imperial.h"
@@ -30,11 +31,13 @@
#include <catch2/catch.hpp>
using namespace units::isq::si;
using namespace units::isq::si::references;
using namespace units::isq::si::international;
using namespace units::isq::si::us;
using namespace units::isq::si::iau;
using namespace units::isq::si::imperial;
using namespace units::isq::si::typographic;
using namespace units::isq::iec80000::references;
TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
{
@@ -97,8 +100,8 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
SECTION("density")
{
CHECK(fmt::format("{}", 1_q_kg_per_m3) == "1 kg/m³");
CHECK(fmt::format("{:%Q %Aq}", 1_q_kg_per_m3) == "1 kg/m^3");
CHECK(fmt::format("{}", 1_q_kg_per_m3) == "1 kg/m³");
CHECK(fmt::format("{:%Q %Aq}", 1_q_kg_per_m3) == "1 kg/m^3");
}
SECTION("resistance")
@@ -116,13 +119,13 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
SECTION("voltage")
{
CHECK(fmt::format("{}", 1_q_V) == "1 V");
CHECK(fmt::format("{}", 1_q_mV) == "1 mV");
CHECK(fmt::format("{}", 1_q_uV) == "1 µV");
CHECK(fmt::format("{}", 1_q_nV) == "1 nV");
CHECK(fmt::format("{}", 1_q_pV) == "1 pV");
CHECK(fmt::format("{}", 1_q_V) == "1 V");
CHECK(fmt::format("{}", 1_q_mV) == "1 mV");
CHECK(fmt::format("{}", 1_q_uV) == "1 µV");
CHECK(fmt::format("{}", 1_q_nV) == "1 nV");
CHECK(fmt::format("{}", 1_q_pV) == "1 pV");
CHECK(fmt::format("{:%Q %Aq}", 1_q_uV) == "1 uV");
CHECK(fmt::format("{:%Q %Aq}", 1_q_uV) == "1 uV");
}
SECTION("volume")
@@ -310,6 +313,37 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
CHECK(fmt::format("{}", 1_q_Nm_per_rad) == "1 N ⋅ m/rad");
}
SECTION("storage_capacity")
{
CHECK(fmt::format("{}", 1 * bit) == "1 bit");
CHECK(fmt::format("{}", 1 * kbit) == "1 kbit");
CHECK(fmt::format("{}", 1 * Tibit) == "1 Tibit");
CHECK(fmt::format("{}", 1 * B) == "1 B");
CHECK(fmt::format("{}", 1 * kB) == "1 kB");
CHECK(fmt::format("{}", 1 * TiB) == "1 TiB");
}
SECTION("transfer_rate")
{
CHECK(fmt::format("{}", 1 * (B / s)) == "1 B/s");
CHECK(fmt::format("{}", 1 * (kB / s)) == "1 kB/s");
CHECK(fmt::format("{}", 1 * (TB / s)) == "1 TB/s");
}
SECTION("traffic_intesity")
{
CHECK(fmt::format("{}", 1 * E) == "1 E");
}
SECTION("modulation_rate")
{
using namespace units::isq::iec80000;
CHECK(fmt::format("{}", 1 * Bd) == "1 Bd");
CHECK(fmt::format("{}", 1 * kBd) == "1 kBd");
CHECK(fmt::format("{}", 1 * TBd) == "1 TBd");
CHECK(fmt::format("{}", quantity_cast<baud>(4 / (2 * s))) == "2 Bd");
}
SECTION("incoherent units with powers")
{
CHECK(fmt::format("{}", 1_q_mi * 1_q_mi * 1_q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");