Deduced units symbols refactoring started

This commit is contained in:
Mateusz Pusz committed 2019-11-04 06:45:56 +00:00
1 parent 7e844ef773
commit 91bcfedf1e
31 files changed
+329 -128

No files matched your search

@@ -38,9 +38,9 @@ namespace data {
struct kibi : units::prefix<kibi, data_prefix, units::ratio< 1'024>, "Ki"> {};
struct mebi : units::prefix<mebi, data_prefix, units::ratio<1'048'576>, "Mi"> {};
struct bit : units::coherent_derived_unit<bit, "b", digital_information, data_prefix> {};
struct bit : units::named_coherent_derived_unit<bit, "b", digital_information, data_prefix> {};
struct kilobit : units::prefixed_derived_unit<kilobit, kibi, bit> {};
struct byte : units::derived_unit<byte, "B", digital_information, units::ratio<8>> {};
struct byte : units::named_derived_unit<byte, "B", digital_information, units::ratio<8>> {};
struct kilobyte : units::prefixed_derived_unit<kilobyte, kibi, byte> {};
inline namespace literals {
+43 -7
View File
@@ -46,15 +46,51 @@ TEST_CASE("operator<< on a quantity", "[text][ostream]")
SECTION("floating-point representation")
{
stream << 72.5kJ;
REQUIRE(stream.str() == "72.5 kJ");
stream << 1023.5Pa;
REQUIRE(stream.str() == "1023.5 Pa");
}
}
SECTION("unit with a prefix")
SECTION("quantity with a predefined unit + prefix")
{
SECTION("in terms of base units")
{
stream << 125us;
REQUIRE(stream.str() == "125 µs");
}
SECTION("in terms of derived units")
{
stream << 60kJ;
REQUIRE(stream.str() == "60 kJ");
}
}
SECTION("quantity with a deduced unit")
{
SECTION("coherent derived unit")
{
SECTION("acceleration")
{
stream << 20.m / 2s / 1s;
REQUIRE(stream.str() == "10 m/s²");
}
SECTION("volume")
{
stream << 2m * 1m * 1m;
REQUIRE(stream.str() == "2 m³");
}
}
SECTION("deduced derived unit")
{
SECTION("velocity")
{
stream << 20.km / 2h;
REQUIRE(stream.str() == "10 km/h");
}
}
}
SECTION("quantity with a predefined dimension but unknown unit")
@@ -68,7 +104,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream]")
SECTION("unit::ratio for a dimension without a special symbol")
{
stream << 2.cm * 2m * 2m;
REQUIRE(stream.str() == "8 [1/100]m^3");
REQUIRE(stream.str() == "8 [1/100]m³");
}
SECTION("unit::ratio::num != 1 && unit::ratio::den == 1")
@@ -131,19 +167,19 @@ TEST_CASE("operator<< on a quantity", "[text][ostream]")
SECTION("exp::num == 2 && exp::den == 1 for positive exponent")
{
stream << 4m * 2s * 2s;
REQUIRE(stream.str() == "16 m⋅s^2");
REQUIRE(stream.str() == "16 m⋅s²");
}
SECTION("exp::num == 2 && exp::den == 1 for negative exponent (first dimension)")
{
stream << 8.s / 2m / 2m;
REQUIRE(stream.str() == "2 1/m^2⋅s");
REQUIRE(stream.str() == "2 1/m²⋅s");
}
SECTION("exp::num == 2 && exp::den == 1 for negative exponent (not first dimension)")
{
stream << 8.m / 2kg / 2kg;
REQUIRE(stream.str() == "2 m/kg^2");
REQUIRE(stream.str() == "2 m/kg²");
}
SECTION("fractional positive exponent")
+6 -6
View File
@@ -30,12 +30,12 @@ namespace cgs {
using units::centimetre;
using units::gram;
using units::second;
struct centimetre_per_second : units::deduced_derived_unit<centimetre_per_second, "cm/s", units::velocity, centimetre, second> {};
struct gal : units::deduced_derived_unit<gal, "Gal", units::acceleration, centimetre, second> {};
struct dyne : units::deduced_derived_unit<dyne, "dyn", units::force, centimetre, gram, second> {};
struct erg : units::deduced_derived_unit<erg, "erg", units::energy, centimetre, gram, second> {};
struct ergps : units::deduced_derived_unit<ergps, "erg/s", units::power, centimetre, gram, second> {};
struct barye : units::deduced_derived_unit<barye, "Ba", units::pressure, centimetre, gram, second> {};
struct centimetre_per_second : units::deduced_derived_unit<centimetre_per_second, units::velocity, centimetre, second> {};
struct gal : units::named_deduced_derived_unit<gal, "Gal", units::acceleration, centimetre, second> {};
struct dyne : units::named_deduced_derived_unit<dyne, "dyn", units::force, centimetre, gram, second> {};
struct erg : units::named_deduced_derived_unit<erg, "erg", units::energy, centimetre, gram, second> {};
struct ergps : units::named_deduced_derived_unit<ergps, "erg/s", units::power, centimetre, gram, second> {}; // TODO make it work for erg and non-named
struct barye : units::named_deduced_derived_unit<barye, "Ba", units::pressure, centimetre, gram, second> {};
inline namespace literals {
+4 -4
View File
@@ -39,10 +39,10 @@ namespace {
struct kibi : units::prefix<kibi, data_prefix, units::ratio< 1'024>, "Ki"> {};
struct bit : units::coherent_derived_unit<bit, "b", digital_information, data_prefix> {};
struct bit : units::named_coherent_derived_unit<bit, "b", digital_information, data_prefix> {};
struct kilobit : units::prefixed_derived_unit<kilobit, kibi, bit> {};
struct byte : units::derived_unit<byte, "B", digital_information, units::ratio<8>> {};
struct byte : units::named_derived_unit<byte, "B", digital_information, units::ratio<8>> {};
struct kilobyte : units::prefixed_derived_unit<kilobyte, kibi, byte> {};
inline namespace literals {
@@ -71,11 +71,11 @@ namespace {
// power spectral density
struct power_spectral_density : derived_dimension<power_spectral_density, units::exp<voltage, 2>, units::exp<frequency, -1>> {};
struct sq_volt_per_hertz : coherent_derived_unit<sq_volt_per_hertz, "V^2/Hz", power_spectral_density> {};
struct sq_volt_per_hertz : coherent_derived_unit<sq_volt_per_hertz, power_spectral_density> {};
// amplitude spectral density
struct amplitude_spectral_density : derived_dimension<amplitude_spectral_density, units::exp<voltage, 1>, units::exp<frequency, -1, 2>> {};
struct volt_per_sqrt_hertz : coherent_derived_unit<volt_per_sqrt_hertz, "V/Hz^(1/2)", amplitude_spectral_density> {};
struct volt_per_sqrt_hertz : coherent_derived_unit<volt_per_sqrt_hertz, amplitude_spectral_density> {};
}
namespace {
+37 -4
View File
@@ -48,10 +48,6 @@ namespace {
/* ************** BASE DIMENSIONS **************** */
// time
static_assert(1h == 3600s);
// length
static_assert(1km == 1000m);
@@ -69,6 +65,33 @@ namespace {
static_assert(5in + 8cm == 207mm);
static_assert(millimetre::symbol == "mm");
static_assert(centimetre::symbol == "cm");
static_assert(kilometre::symbol == "km");
// mass
static_assert(1kg == 1000g);
static_assert(kilogram::symbol == "kg");
// time
static_assert(1h == 3600s);
static_assert(nanosecond::symbol == "ns");
static_assert(microsecond::symbol == "µs");
static_assert(millisecond::symbol == "ms");
// current
// temperature
// substance
// luminous intensity
/* ************** DERIVED DIMENSIONS WITH NAMED UNITS **************** */
// frequency
@@ -80,6 +103,12 @@ namespace {
static_assert(3.2GHz == 3'200'000'000Hz);
static_assert(10Hz * 1min == 600);
static_assert(millihertz::symbol == "mHz");
static_assert(kilohertz::symbol == "kHz");
static_assert(megahertz::symbol == "MHz");
static_assert(gigahertz::symbol == "GHz");
static_assert(terahertz::symbol == "THz");
// force
static_assert(10kg * 10mps_sq == 100N);
@@ -134,6 +163,10 @@ namespace {
// static_assert(2000m / 2kmph == 1h); // should not compile
static_assert(quantity_cast<quantity<kilometre, int>>(2000m) / 2kmph == 1h);
// static_assert(metre_per_second::symbol == basic_fixed_string("m/s"));
// static_assert(kilometre_per_hour::symbol == basic_fixed_string("km/h"));
// acceleration
static_assert(10mps / 10s == 1mps_sq);