Files
uLib/src/Math/testing/UnitsTest.cpp
AndreaRigoni a142c5d060 add units
2026-03-13 21:40:14 +00:00

72 lines
2.1 KiB
C++

/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library.
//////////////////////////////////////////////////////////////////////////////*/
#include "testing-prototype.h"
#include "Math/Units.h"
#include <cmath>
using namespace uLib;
int main()
{
BEGIN_TESTING(Math Units);
// Length
TEST0(1.0_m != 1000.0);
TEST0(1_m != 1000.0);
TEST0(1.0_cm != 10.0);
TEST0(1_cm != 10.0);
TEST0(1.0_mm != 1.0);
TEST0(1_mm != 1.0);
TEST0(1.0_km != 1000000.0);
TEST0(1_km != 1000000.0);
TEST0(std::abs(1.0_um - 1e-3) > 1e-12);
TEST0(std::abs(1.0_nm - 1e-6) > 1e-15);
// Angle
TEST0(std::abs(180.0_deg - M_PI) > 1e-9);
TEST0(std::abs(180_deg - M_PI) > 1e-9);
TEST0(std::abs(1.0_rad - 1.0) > 1e-9);
// Time
TEST0(1.0_s != 1e9);
TEST0(1_s != 1e9);
TEST0(1.0_ms != 1e6);
TEST0(1_ms != 1e6);
TEST0(1.0_ns != 1.0);
TEST0(1_ns != 1.0);
// Energy
TEST0(1.0_MeV != 1.0);
TEST0(1_MeV != 1.0);
TEST0(1.0_GeV != 1000.0);
TEST0(1_GeV != 1000.0);
TEST0(1.0_TeV != 1000000.0);
TEST0(1.0_keV != 1e-3);
TEST0(1.0_eV != 1e-6);
END_TESTING;
}