Files
mp-units/test/unit_test/static/cgs_test.cpp

104 lines
3.2 KiB
C++
Raw Normal View History

2019-11-02 13:59:11 +01:00
// 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.
2019-12-09 17:19:58 +01:00
#include <units/physical/cgs/acceleration.h>
#include <units/physical/cgs/energy.h>
#include <units/physical/cgs/force.h>
#include <units/physical/cgs/length.h>
#include <units/physical/cgs/mass.h>
#include <units/physical/cgs/power.h>
#include <units/physical/cgs/pressure.h>
#include <units/physical/cgs/time.h>
#include <units/physical/cgs/speed.h>
2019-11-02 13:59:11 +01:00
namespace {
2019-12-09 17:19:58 +01:00
using namespace units;
using namespace units::physical::cgs;
2019-12-09 17:19:58 +01:00
2019-12-11 16:20:08 +01:00
/* ************** BASE DIMENSIONS **************** */
2019-12-09 17:19:58 +01:00
2019-12-11 16:20:08 +01:00
// length
2019-12-09 17:19:58 +01:00
2019-12-11 16:20:08 +01:00
static_assert(centimetre::symbol == "cm");
2019-12-09 17:19:58 +01:00
2019-12-11 16:20:08 +01:00
// mass
2019-11-02 13:59:11 +01:00
2019-12-11 16:20:08 +01:00
// time
2019-11-02 13:59:11 +01:00
2019-12-11 16:20:08 +01:00
/* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */
2019-12-09 17:19:58 +01:00
// speed
2019-12-09 17:19:58 +01:00
2020-03-10 20:53:53 +01:00
static_assert(10q_cm / 5q_s == 2q_cm_per_s);
static_assert(10q_cm / 2q_cm_per_s == 5q_s);
static_assert(10q_cm == 2q_cm_per_s * 5q_s);
2019-12-09 17:19:58 +01:00
2020-05-14 16:00:38 +02:00
static_assert(detail::unit_text<dim_speed, centimetre_per_second>() == "cm/s");
2019-12-09 17:19:58 +01:00
2019-12-11 16:20:08 +01:00
// area
static_assert(std::is_same_v<ratio_divide<centimetre::ratio, dimension_unit<dim_length>::ratio>, ratio<1>>);
2020-02-17 15:56:06 +01:00
static_assert(1q_cm * 1q_cm == 1q_cm2);
static_assert(100q_cm2 / 10q_cm == 10q_cm);
2019-12-11 16:20:08 +01:00
2020-03-27 15:21:05 +01:00
static_assert(detail::unit_text<dim_area, square_centimetre>() == basic_symbol_text("cm²", "cm^2"));
2019-12-11 16:20:08 +01:00
/* ************** DERIVED DIMENSIONS WITH NAMED UNITS **************** */
// acceleration
2020-03-10 20:53:53 +01:00
static_assert(10q_cm_per_s / 10q_s == 1q_Gal);
static_assert(10q_cm_per_s / 1q_Gal == 10q_s);
static_assert(1q_Gal * 10q_s == 10q_cm_per_s);
2019-12-11 16:20:08 +01:00
// force
2020-02-17 15:56:06 +01:00
static_assert(10q_g * 10q_Gal == 100q_dyn);
static_assert(100q_dyn / 10q_g == 10q_Gal);
static_assert(100q_dyn / 10q_Gal == 10q_g);
2019-12-11 16:20:08 +01:00
// pressure
2020-02-17 15:56:06 +01:00
static_assert(10q_dyn / 10q_cm2 == 1q_Ba);
static_assert(10q_dyn / 1q_Ba == 10q_cm2);
static_assert(1q_Ba * 10q_cm2 == 10q_dyn);
2019-12-11 16:20:08 +01:00
// energy
2020-02-17 15:56:06 +01:00
static_assert(10q_dyn * 10q_cm == 100q_erg);
static_assert(100q_erg / 10q_cm == 10q_dyn);
static_assert(100q_erg / 10q_dyn == 10q_cm);
2019-12-11 16:20:08 +01:00
/* ************** DERIVED DIMENSIONS IN TERMS OF OTHER UNITS **************** */
// power
2020-03-10 20:53:53 +01:00
static_assert(10q_erg / 10q_s == 1q_erg_per_s);
static_assert(1q_erg_per_s * 10q_s == 10q_erg);
static_assert(10q_erg / 1q_erg_per_s == 10q_s);
2019-12-11 16:20:08 +01:00
static_assert(detail::unit_text<dim_power, erg_per_second>() == "erg/s");
2019-12-09 17:19:58 +01:00
}