IAP GITLAB

Skip to content
Snippets Groups Projects
testUnits.cc 3.15 KiB

/**
 * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
 *
 * See file AUTHORS for a list of contributors.
 *
 * This software is distributed under the terms of the GNU General Public
 * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
 * the license.
 */

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one
                          // cpp file
#include <catch2/catch.hpp>

#include <corsika/units/PhysicalUnits.h>

#include <array>

using namespace corsika;
using namespace corsika::units::si;

TEST_CASE("PhysicalUnits", "[Units]") {

  SECTION("Consistency") {
    REQUIRE(1_m / 1_m == Approx(1));
    // REQUIRE_FALSE( 1_m/1_s == 1 ); // static assert
  }

  SECTION("Constructors") {
    [[maybe_unused]] auto E1 = 10_GeV;
    REQUIRE(E1 == 10_GeV);

    LengthType l1 = 10_nm;
    l1 = l1;

    LengthType arr0[5];
    arr0[0] = 5_m;

    [[maybe_unused]] LengthType arr1[2] = {{1_mm}, {2_cm}};

    std::array<EnergyType, 4> arr2; // empty array

    [[maybe_unused]] std::array<EnergyType, 4> arr3 = {1_GeV, 1_eV, 5_MeV};

    [[maybe_unused]] auto p1 = 10_newton_second;
    REQUIRE(p1 == 10_newton_second);
  }

  SECTION("Powers in literal units") {
    REQUIRE(1_s / 1_ds == Approx(1e1));
    REQUIRE(1_m / 1_cm == Approx(1e2));
    REQUIRE(1_m / 1_mm == Approx(1e3));
    REQUIRE(1_V / 1_uV == Approx(1e6));
    REQUIRE(1_s / 1_ns == Approx(1e9));
    REQUIRE(1_eV / 1_peV == Approx(1e12));
    REQUIRE(1_A / 1_fA == Approx(1e15));
    REQUIRE(1_mol / 1_amol == Approx(1e18));
    REQUIRE(1_K / 1_zK == Approx(1e21));
    REQUIRE(1_K / 1_yK == Approx(1e24));
    REQUIRE(1_barn / 1_mbarn == Approx(1e3));

    REQUIRE(1_A / 1_hA == Approx(1e-2));
    REQUIRE(1_m / 1_km == Approx(1e-3));
    REQUIRE(1_m / 1_Mm == Approx(1e-6));
    REQUIRE(1_V / 1_GV == Approx(1e-9));
    REQUIRE(1_s / 1_Ts == Approx(1e-12));
    REQUIRE(1_eV / 1_PeV == Approx(1e-15));
    REQUIRE(1_A / 1_EA == Approx(1e-18));
    REQUIRE(1_K / 1_ZK == Approx(1e-21));