forked from mpusz/mp-units
feat: 💥 !data system renamed to isq::iec80000 (quantity names renamed too)
Relates to #253
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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³");
|
||||
|
||||
@@ -44,11 +44,11 @@ add_library(unit_tests_static
|
||||
concepts_test.cpp
|
||||
custom_rep_test_min_expl.cpp
|
||||
custom_unit_test.cpp
|
||||
data_test.cpp
|
||||
dimension_op_test.cpp
|
||||
dimensions_concepts_test.cpp
|
||||
fixed_string_test.cpp
|
||||
fps_test.cpp
|
||||
iec80000_test.cpp
|
||||
kind_test.cpp
|
||||
math_test.cpp
|
||||
ratio_test.cpp
|
||||
|
||||
@@ -20,31 +20,41 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/data/data.h>
|
||||
#include <units/isq/iec80000/iec80000.h>
|
||||
|
||||
/* ************** DERIVED DIMENSIONS THAT INCLUDE UNITS WITH SPECIAL NAMES **************** */
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units::data;
|
||||
using namespace units::isq::si::references;
|
||||
using namespace units::isq::iec80000::references;
|
||||
|
||||
// information
|
||||
|
||||
static_assert(1_q_B == 8_q_b);
|
||||
static_assert(1024_q_b == 1_q_Kib);
|
||||
static_assert(1024_q_B == 1_q_KiB);
|
||||
static_assert(8 * 1024_q_b == 1_q_KiB);
|
||||
static_assert(8 * 1_q_Kib == 1_q_KiB);
|
||||
static_assert(1 * B == 8 * bit);
|
||||
static_assert(1024 * bit == 1 * Kibit);
|
||||
static_assert(1024 * B == 1 * KiB);
|
||||
static_assert(8 * 1024 * bit == 1 * KiB);
|
||||
static_assert(8 * 1 * Kibit == 1 * KiB);
|
||||
|
||||
static_assert(1_q_kb == 1000_q_b);
|
||||
static_assert(2000_q_Mib == 2097152_q_kb);
|
||||
static_assert(1 * kbit == 1000 * bit);
|
||||
static_assert(2000 * Mibit == 2097152 * kbit);
|
||||
|
||||
static_assert(1_q_Kib == 1024_q_b);
|
||||
static_assert(1_q_Mib == 1024_q_Kib);
|
||||
static_assert(1_q_Gib == 1024_q_Mib);
|
||||
static_assert(1_q_Tib == 1024_q_Gib);
|
||||
static_assert(1_q_Pib == 1024_q_Tib);
|
||||
static_assert(1 * Kibit == 1024 * bit);
|
||||
static_assert(1 * Mibit == 1024 * Kibit);
|
||||
static_assert(1 * Gibit == 1024 * Mibit);
|
||||
static_assert(1 * Tibit == 1024 * Gibit);
|
||||
static_assert(1 * Pibit == 1024 * Tibit);
|
||||
static_assert(1 * Eibit == 1024 * Pibit);
|
||||
|
||||
// bitrate
|
||||
// transfer rate
|
||||
|
||||
static_assert(16 * B / (2 * s) == 8 * (B / s));
|
||||
static_assert(120 * kB / (2 * min) == 1000 * (B / s));
|
||||
|
||||
// modulation rate
|
||||
|
||||
static_assert(12 / (2 * s) == 6 * Bd);
|
||||
static_assert(6000 / (3 * s) == 2 * kBd);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user